admin管理员组文章数量:1336118
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. This code works in IE6, IE7, FF3, and Safari... Any ideas? Does it have something to do with the '$(this)' selector in the switch? 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; } }); }
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. This code works in IE6, IE7, FF3, and Safari... Any ideas? Does it have something to do with the '$(this)' selector in the switch? 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; } }); }Share edited Apr 24, 2009 at 18:48 Chris Voth asked Apr 24, 2009 at 18:42 Chris VothChris Voth 8535 gold badges13 silver badges22 bronze badges 3
- No clues as to which line? IE 8 does have a built in script debugger. – Greg Commented Apr 24, 2009 at 18:49
- The error is ing from the Jquery Library file, not my javascript file... Line 14 'value=jQuery.browser.msie&&!option.attributes.value.specified?option.text:option.value' – Chris Voth Commented Apr 24, 2009 at 18:52
- Thanks for removing the extra cases as they weren't adding anything to the example, but I'd like to say it makes my point stronger as well: Use this more generic approach and you'll be able to change it easier in the future. – cgp Commented Apr 24, 2009 at 18:52
2 Answers
Reset to default 3Oh 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" parison.
I upgraded the jQuery library from 1.2.6 to 1.3.2 and this solved the problem. Didn't realize I had an old version- oops.
Thanks for your help all!
本文标签: IE8 Jquery Javascript quotError Object requiredquot BugStack Overflow
版权声明:本文标题:IE8 Jquery Javascript "Error: Object required" Bug - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742403613a2468373.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论