简体   繁体   中英

JQuery in external JS file

I am trying to execute some JavaScript when my html page loads. The top method populateSelectWithDates() is called, but the jquery portion does not. Any ideas?

function doInitialPopulation() {
    //This works
    populateSelectWithDates();

    //This does not
    $(document).ready(function() {
        alert('ok');
    //Credit to: http://www.pewpewlaser.com/articles/jquery-tablesorter
        //  Adds sort_header class to ths
        $(".sortable th").addClass("sort_header");

        //  Adds alternating row coloring to table.
        $(".sortable").tablesorter({widgets: ["zebra"]});

        //  Adds "over" class to rows on mouseover
        $(".sortable tr").mouseover(function() {
            $(this).addClass("over");
        });

        //  Removes "over" class from rows on mouseout
        $(".sortable tr").mouseout(function() {
            $(this).removeClass("over");
        });

    });
}

In your HTML file, make sure you are including the scripts in this order:

<!-- first include jQuery -->
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<!-- then include your script(s) -->
<script src="YOUR_SCRIPT.js" type="text/javascript"></script>

我看不到$(document).ready(function() {任何使用。尝试将其删除。让我们知道alert('ok')是否有效。我们还能看到函数populateSelectWithDates()吗?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM