[英]IE8 Jquery Javascript “Error: Object required” Bug
IE8 throws an "Error: Object required" message (error in the actual jquery library script, not my javascript file) when the switch statement in this function runs. 当此函数中的switch语句运行时,IE8会引发“错误:需要对象”消息(实际的jquery库脚本中的错误,而不是我的javascript文件中的错误)。 This code works in IE6, IE7, FF3, and Safari... Any ideas?
该代码可在IE6,IE7,FF3和Safari中工作...有什么想法吗? Does it have something to do with the '$(this)' selector in the switch?
它与开关中的'$(this)'选择器有关吗? Thanks!
谢谢!
function totshirts(){ $('.shirt-totals input').val('0'); var cxs = 0; var cs = 0; var cm = 0; $.each($('select.size'), function() { switch($(this).val()){ case "cxs": cxs ++; $('input[name="cxs"]').val(cxs); break; case "cs": cs ++; $('input[name="cs"]').val(cs); break; case "cm": cm ++; $('input[name="cm"]').val(cm); break; } }); }
Oh noes, don't do it that way at all. 哦,不,根本不要那样做。
Do something more along the lines of this: 按照以下方式做更多事情:
$('.shirt-totals input').val('0');
$('select.size').each(function() {
var name = $(this).attr('name');
var currVal = parseInt($("input[name='"+name+"']").val());
$("input[name='"+name+"']").val(currVal+1);
});
As a sidenote, I tend to find that jQuery seems to deal with single quotes better than doubles in when doing the "equals" comparison. 作为附带说明,我倾向于发现在进行“等于”比较时,jQuery处理单引号似乎比使用双引号更好。
I upgraded the jQuery library from 1.2.6 to 1.3.2 and this solved the problem. 我将jQuery库从1.2.6升级到1.3.2,这解决了问题。 Didn't realize I had an old version- oops.
没意识到我有一个旧版本。
Thanks for your help all! 感谢大家的帮助!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.