2016-01-20 95 views
-2

我需要使用jquery在表中加载elem。这是代码:为什么脚本只能在我重新加载页面?

在file.html表的代码是:

<table id="tabella_ban_email" class="table table-condensed table-responsive table-hover"></table> 

,并在的script.js的代码是:

$(document).ready(function() { 
    var email_table=$('#tabella_ban_email'); 
    if(email_table!=null && email_table!=undefined){ 
    $.ajax({ 
     url:'....', 
     success: function(data) { 
     data.split(',').forEach(function(email){ 
      email_table.append('<tr><th>'+email+'</th><th><input type="button" name="'+email+'" value="X">'); 
     }); 
     } 
    }); 
    } 
}); 

该程序仅适用于我刷新页面,如果我不重新加载页面程序不起作用。

+0

查看控制台以获取更多信息? –

+1

也许是因为它只存在于'document.ready()'函数中,你有没有想过?真的想想'document.ready()'被调用吗? –

+1

[脚本只在页面重新加载时工作]的完全重复(http://stackoverflow.com/questions/3969144/script-working-only-on-page-reload?rq=1)。你问之前甚至搜索过吗? –

回答

0
$(document).ready(function() { 
// executes when HTML-Document is loaded and DOM is ready 
alert("document is ready"); 
}); 


$(window).load(function() { 
// Executes when page is fully loaded 
alert("window is loaded"); 
}); 

Use $(window).load ... it might work in your scenario 
+0

它不起作用! – adsds

+0

我有两个问题,即1)(文档).ready被称为? 2)如果它被称为'email_table'包含什么? – suresh

+0

我认为这是一个加载问题。脚本执行时,页面的组件不会加载。用你的建议,我用我的代码 – adsds

相关问题