Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/395.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Ajax加载内容,jquery插件不工作_Javascript_Jquery_Ajax_Sorting_Tablesorter - Fatal编程技术网

Javascript Ajax加载内容,jquery插件不工作

Javascript Ajax加载内容,jquery插件不工作,javascript,jquery,ajax,sorting,tablesorter,Javascript,Jquery,Ajax,Sorting,Tablesorter,我有一个链接,它调用ajax来加载内容,加载内容后,我的jquery函数就不再工作了 这是我的HTML <a href="#" onclick="javascript:makeRequest('content.html','');">Load Content</a> <span id="result"> <table id="myTable" valign="top" class="tablesorter"> <t

我有一个链接,它调用ajax来加载内容,加载内容后,我的jquery函数就不再工作了

这是我的HTML

 <a href="#" onclick="javascript:makeRequest('content.html','');">Load Content</a>
    <span id="result">
 <table id="myTable" valign="top" class="tablesorter">
        <thead>
          <tr>
            <th>Title 1</th>
            <th>Level 1</th>
            <th>Topics</th>
            <th>Resources</th>
          </tr>
        </thead>
        <tbody>
          <tr>
            <td>Example title 1</td>
            <td>Example level 1</td>
          </tr>
          <tr>
            <td>Example title 2</td>
            <td>Example level 2</td>
          </tr>
        </tbody>
      </table>
</span>
你知道如何在内容加载后让jquery插件工作吗? 我搜索了jquery.tablesorter.js click函数,并将其更改为live(),如下所示
$headers.live(“click”,function(e)

加载内容后,如何使jquery函数工作? 多谢各位


更新测试脚本:

<a href="#" id="test" onClick="contentDisp()">Load Content</a>
<div id="result"></div>

<script type="text/javascript"> 
function contentDisp()
{
$.ajax({
url : "test.html",
success : function (data) {
$("#result").html(data);
$("#myTable").tablesorter();
$("#myTable").trigger("update"); 
}
});
}
</script> 

函数contentDisp()
{
$.ajax({
url:“test.html”,
成功:功能(数据){
$(“#结果”).html(数据);
$(“#myTable”).tablesorter();
$(“#myTable”).trigger(“更新”);
}
});
}
这是我的test.html。如果我不将表排序放在加载的内容中,表排序就会起作用。一旦它加载到div中,排序就不再起作用了

<table id="myTable" valign="top" class="tablesorter">

    <thead>
      <tr>
        <th class="header">Title 1</th>
        <th class="header">Level 1</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td>Example title 1</td>
        <td>Example level 1</td>
      </tr>
      <tr>
        <td>Example title 2</td>
        <td>Example level 2</td>
      </tr>
    </tbody>
  </table>      

标题1
一级
示例标题1
示例级别1
示例标题2
示例级别2
插入表数据后,需要调用
$(“#myTable”).trigger(“update”);

请看一看,它可能会帮助你清理你的内容加载代码以及


如果您需要更多的帮助/代码,只需发表评论即可。(我认为您最好弄清楚它,而不是填鸭式的填鸭式填鸭式填鸭式填鸭式填鸭式填鸭式填鸭式填鸭式填鸭式填鸭式填鸭式填鸭式填鸭式填鸭式填鸭式填鸭式填鸭式填鸭式填鸭式填鸭式填鸭式填鸭

当jQuery具有内置的加载功能使其变得更容易时,为什么要遇到http_请求的所有问题?我的链接是动态的,我无法分配不同的div id,因此我使用其他ajax方法,您可以访问div id,如
$(“#result”)
。如果您使用jQuery,您可以在返回数据的上下文中访问div。我觉得这对您的情况很有用。谢谢,我编辑了我的脚本。我意识到这不仅发生在表排序上,而且也发生在任何其他jQuery插件上。一旦加载内容,所有jQuery插件都不会在新加载的目录中工作内容。您好,非常感谢您的回答。:)表附加有效,但我不打算附加表。问题是,在使用ajax加载内容后,所有其他jquery函数似乎都无法正常工作(已经得到了答案。非常感谢您的启动!在加载内容并返回成功后,我使用此函数再次调用函数:)$(“.tablesorter”).tablesorter();
<table id="myTable" valign="top" class="tablesorter">

    <thead>
      <tr>
        <th class="header">Title 1</th>
        <th class="header">Level 1</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td>Example title 1</td>
        <td>Example level 1</td>
      </tr>
      <tr>
        <td>Example title 2</td>
        <td>Example level 2</td>
      </tr>
    </tbody>
  </table>