我使用以下方法在特定元素中查找字符串,如果存在,勾选复选框。这在 Firefox 上运行良好,但在 Internet Explorer (8) 上运行不佳。我找不到原因。
$.fn.searchString = function(str) {
return this.filter('*:contains("' + str + '")');
};
var myID = $('div').searchString(files_array[i].substr(-4));
alert(myID);//[object object]
alert(myID.children());//[object object]
myID.children().attr('checked', true);//does not tick checkbox
alert(myID.children().attr('checked'));//undefined
IE不喜欢children()函数吗?
感谢大家的帮助
最佳答案
来自 MSDN,引用“substr”函数:
Remarks
If length is zero or negative, an empty string is returned. If not specified, the substring continues to the end of the string.
您没有从试图设置“myID”的原始代码中得到任何结果。
关于javascript - 适用于 Firefox 但不适用于 IE,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2920884/