[英]JavaScript not working in IE8 / IE7 but fine in every other browser
I am really new to javaScript so please bear with me. 我真的是javaScript的新手,所以请多多包涵。 The code I have used is a mish mash of all sorts. 我使用的代码是各种各样的混搭。
Basically what the script does is calculates a price based on how many pallets they choose and where they are shipping to and from and which zone it is (Four Zones per country) 基本上,脚本的作用是根据他们选择的托盘数量以及它们往返于何处的运费以及它的区域(每个国家四个区域)来计算价格。
All this is working fine but when I comes to IE8 the script doesn't work and I cannot figure out why. 所有这些都工作正常,但是当我使用IE8时,脚本不起作用,我无法弄清原因。
I do see an error when I load the console on IE8. 在IE8上加载控制台时,确实看到错误。 The error is: 错误是:
SCRIPT87: Invalid argument.
Line 437 character 7
which is this line of code 这是这行代码
var fromCountry = document.querySelector('input[name="from_country"]:checked').value;
A working demo is located here - http://jsfiddle.net/barrycorrigan/f3wz6/ 一个有效的演示位于此处-http://jsfiddle.net/barrycorrigan/f3wz6/
I think some of it is Pure JavaScript and some of it is jQuery. 我认为其中有些是纯JavaScript,有些是jQuery。 Does this matter? 这有关系吗? Could this be a problem? 这可能是个问题吗?
Any help on making this code function better would be a great help. 使该代码功能更好的任何帮助将是一个巨大的帮助。
As pointed out in the comments, querySelector
isn't available in IE7. 正如评论中指出的那样,IE7中没有querySelector
。 Since you're using jQuery, you should re-write it like: 由于您使用的是jQuery,因此应将其重写为:
$('input[name="from_country"]:checked').val()
Behind the scenes, jQuery does a check to see if the browser supports the efficient querySelector
method, and if it does, it uses it. 在后台,jQuery进行检查以查看浏览器是否支持有效的querySelector
方法,如果支持,则使用它。 Otherwise, it will fall back to using the broadly compatible Sizzle selector engine. 否则,它将退回到使用广泛兼容的Sizzle选择器引擎。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.