我正在使用 jquery 1.10.2,下面对我的 dialogOpen 函数的调用在 IE9+ 中工作正常,但我在 IE8 中收到以下错误:
对象不支持此属性或方法。有什么想法吗?
dialogOpen($(this).attr("id"), $(this).find(".tdStyle").html().trim(), $(this).find(".tdQtyOnHand").html().trim(), $(this), $(this).find(".tdPlantID").html().trim());
谢谢
最佳答案
.html()
返回一个 String 对象,IE 不支持 String 上的 .trim()
方法,幸运的是 jQuery 提供了一个替代方法,$.trim(String)
.您也可以按照 this exhaustive article 自己添加它(但老实说,jQuery 已经加载了,您为什么要这样做) (这将允许您完全不修改原始代码):
if (!String.prototype.trim) {
String.prototype.trim = function () {
return this.replace(/^\s+|\s+$/gm, '');
};
}
关于javascript - 为什么这个脚本在 IE8 中不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21265929/