我似乎找不到导致 IE 7 在 Chrome 中运行时出现此错误的原因。当在 Internet Explorer 中加载我的页面时,它弹出错误“停止运行此脚本消息”。有什么想法吗?
$(document).ready(function() {
var icons = {
header: "ui-icon-circle-plus",
headerSelected: "ui-icon-circle-minus"
};
$('.ui-accordion').accordion({
active: false,
collapsible: true,
autoHeight: false,
icons: icons
});
$("a").click(function (event) {
event.stopPropagation();
});
$('.requirementCheckBox').click(function() {
getReq();
});
});
function getReq() {
var componentList;
var selected = $(":checkbox:checked");
if(selected.length ==0){
$('#requirements_table_wrapper').remove();
}
else {
$.each(selected , function(i, n){
if(i == 0){
componentList = n.value;
}
else{
componentList += ',' + n.value;
}
});
$.getJSON("addRequirements/GetRequirements/?componentList=" + componentList, function (data) {
$('#requirements_table_wrapper').remove();
var reqString = '<table id="requirements_table"><thead><tr><th>Requirement ID</th><th>Requirements</th><th>Reference</th></tr></thead><tbody>';
for (var i = 0; i < data.length; i++) {
reqString += '<tr><td>'+ data[i].reqID + '</td><td>' + data[i].reqText + '</td>' + '<td>' + data[i].reqReference + '</td></tr>';
}
reqString += '</tbody></table>';
$("#requirementsDiv").append(reqString);
$("#requirements_table").dataTable({
"bJQueryUI": true,
"bPaginate": false,
"bRetrieve": true,
"oLanguage": {"sSearch" : "Filter Requirements:"}
});
});
}
我没有立即发现任何无限循环,但也许我盯着它看的时间太长了。
**更新 问题似乎出在 Accordion 上,一旦它被移除,IE 就会正常加载页面。
最佳答案
使用 $("#requirementsDiv").html(reqString);
而不是 .append()
方法。
$elem.html(string)
等同于 elem.innerHTML = string
。
$elem.append(string)
首先将字符串转换为 DOM 元素,然后使用 DOM .appendChild()
方法将元素附加到 HTML。
由于您是在页面加载时执行代码,因此 div 的内容很可能是空的。如果 div 不为空,但不包含事件处理程序等,也可以使用 .html()
:
var $elem = $("#requirementsDiv");
$elem.html($elem.html() + reqString);
关于javascript - IE 7 "stop running this script"错误使用 jQuery,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7972744/