jQuery AJAX加载IE6问题


                    

我有一个包含所有jQuery和JavaScript文件的主HTML文件。 现在,我有一个具有扩展/折叠功能的表。 该表位于其他HTML文件中。</ p>

我正在尝试将表加载到主文件中。 我已成功将表加载到主HTML文件中,但是扩展/折叠仅在IE6 / IE7中不起作用。 在FF,Chrome,Safari和IE8中可以正常工作。</ p>

local.js具有展开/折叠代码

table.html是仅包含表代码而没有JavaScript的html文件。</ p>

主要HTML:</ strong> </ p>

  
     主要html </ title>
     <头>
         &lt;/ script&gt;<br>          <script type =“ text / javascript” scr =“ localjs.js”> &lt;/ script&gt;<br>          <script type =“ text / javascript”></p> <p>             $(&#39;#ajaxtable&#39;)。load(&#39;ajax / table.html&#39;,function(){<br>                  alert(&#39;表已加载。&#39;);<br>              });</p> <p>         &lt;/ script&gt;<br>      &lt;/ head&gt;</p> <p>     &lt;身体&gt;<br>          <div id =“ ajaxtable”> &lt;/ div&gt;<br>      &lt;/ body&gt;<br> &lt;/ html&gt;<br> &lt;/ code&gt; &lt;/ pre&gt;</p> <p><p>我可以看到该表已加载到ajaxtable div中,但扩展/折叠仅在IE6中不起作用。 &lt;/ p&gt;<br>      &lt;/ div&gt;</p>

展开原文

原文

I have a main HTML file with all the jQuery and JavaScript files included in it. Now I have a table which has a expand/collapse functionality. This table is in a different HTML file.

I am trying to load the table in the main file. I was successful in loading the table in the main HTML file but the expand/collapse is not working only in IE6/IE7. This works fine in FF, Chrome, Safari and IE8.

local.js has the expand/collapse code
table.html is the html file which has only the table code and no JavaScript.

MAIN HTML:

<html>
    <title>Main html</title>
    <head>
        <script type="text/javascript" src="jquery.js"></script>
        <script type="text/javascript" scr="localjs.js"></script>
        <script type="text/javascript">

            $('#ajaxtable').load('ajax/table.html', function() {
                alert('Table Loaded.');
            });

        </script>
    </head>

    <body>
        <div id="ajaxtable"></div>
    </body>
</html>

I can see the table gets loaded in the ajaxtable div but the expand/collapse is not working only in IE6.

1个回答


正如我在上面的评论中提到的,您正在 $('#ajaxtable')</ code>调用之前加载 localjs.js </ code>。 在创建表之后,请附加单击处理程序,您应该可以... </ p>

  <br>
 $(&#39;#ajaxtable&#39;)。load(&#39;ajax / table.html&#39;,function(){<br>
   alert(&#39;表已加载。&#39;);<br>
   $(&#39;table tr.heading&#39;)。click(function(){$(tr.alpha).slideToggle(&#39;slow&#39;);});<br>
 });<br>
 &lt;/ script&gt;<br>
 &lt;/ code&gt; &lt;/ pre&gt;<br>
     &lt;/ div&gt;</p>

展开原文

原文

As I mentioned in my comment above, you are loading localjs.js before the $('#ajaxtable') call. Attach the click handler after the table has been created and you should be fine...

<script type="text/javascript">
$('#ajaxtable').load('ajax/table.html', function() {
  alert('Table Loaded.');
  $('table tr.heading').click(function(){ $(tr.alpha).slideToggle('slow'); });
});
</script>

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问