为什么脚本只工作 我重新加载页面

Why the script works only I reload the page?

本文关键字:加载 新加载 脚本 工作 为什么      更新时间:2023-09-26

我需要使用 jquery 在表中加载 elem。这是代码:

在文件中.html表的代码为:

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

在脚本中.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">');
        });
      }
    });
  }
});

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

$(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