Reusing JS code from a bootstrap-datepicker

0

I have a bootstrap-datepicker with the following JS:

    $(document).ready(function() 
        {
            var dataIni = $("#calendarioIni");
            var dataFim = $("#calendarioFim");

            $('#calendarioIni').datepicker({
                startDate: '01/01/1998', 
                endDate: '31/12/1998', 
                dateFormat: 'dd/mm/yy',

            });

            $('#calendarioFim').datepicker({
                startDate: '01/01/1998',
                endDate: '31/12/1998', 
                dateFormat: 'dd/mm/yy',

            });
 });

But I will use it on several pages in my project, how could I do code reuse?

    
asked by anonymous 19.12.2017 / 16:32

1 answer

1

If on all pages the element id is the same you can simply add this code snippet to a .js and import it into every page so when you want to make any changes just modify the .js

It would look like this:

<script src="seu-arquivo.js" type="application/javascript"></script>

Inside of your .html pages

    
19.12.2017 / 16:35