2013-10-31 62 views
0

我想在我的html页面加载时执行一些JavaScript。顶部方法populateSelectWithDates()被调用,但jquery部分没有。有任何想法吗?外部JS文件中的JQuery

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"); 
     }); 

    }); 
} 
+1

你是否包含'jQuery library' .Check'console'来查找错误。 –

+0

你有没有列出你的文件之前的jquery文件? – EmptyArsenal

+0

我是否在外部js文件或html文件中执行jquery导入? – user1154644

回答

1

在你的HTML文件,请确保你包括在该命令的脚本:

<!-- 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> 
0

我没有看到任何使用$(document).ready(function() {尝试删除它。让我们知道警报('OK')是否有效。我们也可以看到功能populateSelectWithDates()