IE7和jQuery .html/.empty/.css无法触发 [英] IE7 and jQuery .html / .empty / .css not firing

查看:96
本文介绍了IE7和jQuery .html/.empty/.css无法触发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个页面,使用一堆由.NET中继器在page_load上生成的表.这些表可以具有以下两个类别之一:fileExistsfileDoesNotExist.在document.ready上,我具有以下内容:

I have a page using a bunch of tables that are generated by a .NET repeater on page_load. These tables can have one of two classes: fileExists or fileDoesNotExist. On document.ready, I have the following:

$document.ready(function () {
    $('.fileDoesNotExist').each(function () {
        $(this).html("<h3>FILE #" + $(this).attr('id').replace('T', '') + ":</h3><p><a href=\"/cp/media-upload.aspx?seq=" + $(this).attr('id').replace('T', '') + "\">click here to upload an MP3 or video</a></p>");
        $(this).css('border', 'none');
    });
});

应该影响HTML的哪些部分(涉及更多元素,但这是基本要点):

Which should affect this bit of HTML (there are more elements involved, but this is the basic gist):

<table class="fileDoesNotExist" style="width: 100%;margin-top: 1em;" id="T1">
        <tr>
            <th colspan="3">FILE 1</th>
        </tr>
        <tr>
        <td>Media Title:</td>
            <td colspan="2">
                <input name="txtTitle" type="text" maxlength="255" size="50" id="txtTitle" />
            </td>
        </tr>
</table>

此代码在Chrome,Firefox,IE8和IE9中正常运行.尝试在IE7中查看页面时,它什么也不做.我可以使用IE7标准以文档模式在IE9中复制它,并且尝试直接在控制台中运行脚本时,它什么也不做,也不返回任何有用的错误消息.

This code fires fine in Chrome, Firefox, IE8 and IE9. When trying to view the page in IE7, it does all of nothing. I can replicate it in IE9 using IE7 standards for the document mode, and when trying to run the script directly in the console, it does all of nothing and returns no helpful error message.

.each肯定是正确触发的(我用alert($(this).attr('id'));替换了$(this).html,并用fileDoesNotExist类吐出了表的ID),但似乎html/css替换项不是'服用.

The .each is definitely properly firing (I replaced the $(this).html with alert($(this).attr('id')); and that spit out the IDs of the tables with the fileDoesNotExist class) but it seems that the html/css replacements just aren't taking.

我在这里缺少IE7的一些时髦功能(除了,就是IE7)吗?我浏览了与我的主题有关的建议问题,但似乎根本没有触发.html或.css的问题.

Is there something funky with IE7 (besides, you know, it being IE7) that I'm missing here? I looked through the suggested questions listed w/ my topic, but nothing seemed to touch upon .html or .css not firing at all.

推荐答案

似乎当将innerHTML应用于Table或TBody元素时,无法在IE7中安全地使用它. 这里有一些参考.

It appears that innerHTML cannot be safely used in IE7 when being applied to Table or TBody elements. here are a couple of references.

IE7中的InnerHTML问题

jQuery .html()not在ie7中显示任何数据,但ie8可以工作

希望有帮助,两者都可以解决问题

hope that helps, both give workarrounds

编辑

由于您的代码用纯HTML替换了Table元素的内容(没有tr/td标签),所以为什么不将表放入包含div的文件中,而是将fileExists/fileDoesNotExist类应用于该div.

Since your code replaces the contents of the Table element with plain html (no tr/td tags) why not put your tables in a containing div and apply the fileExists / fileDoesNotExist classes to that div instead.

带有外部div的JSFiddle

这篇关于IE7和jQuery .html/.empty/.css无法触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆