IE8 中选择元素和 jQuery CHANGE 事件?
我的网站上有一个小脚本,它根据 4 个不同的 Select 元素中选择的选项来计算报价。报价被写入 div 中,并在每次所选选项发生任何变化时更新。
以下是此页面的链接:http://www.justaddsolutions.com/justaddwebsite/prices/
每次我的 Select 元素发生变化时,我都会使用 jQuery CHANGE 事件处理程序来触发计算函数,如下所示:
jQuery("#pages").change(price_quoter);
这是我的 HTML 代码:
<select id="pages" class="instant_quote" name="pages">
<option value="1">1 page</option>
<option value="2">2 pages</option>
这在 Safari 和 Chrome 中工作正常,但不适用在 IE8 中工作。在IE8中,Select元素的变化不会触发计算功能。
我研究了这个问题并得到了相反的数据 - 有些人说 Change jQuery 事件在 IE8 中不起作用,有些人说可以。
然后我想到使用JS的onChange函数,但是又看到IE8不支持。
您能帮忙找出适用于所有浏览器的方法吗?
I have a small script on my site that calculates a price quote based on the options chosen in 4 different Select elements. The price quote is written into a div and is updated each time there is any change in the selected options.
Here is the link to this page: http://www.justaddsolutions.com/justaddwebsite/prices/
I used jQuery CHANGE event handler to trigger the calculating function each time there is a change in my Select elements, like this:
jQuery("#pages").change(price_quoter);
And here is my HTML code that goes with it:
<select id="pages" class="instant_quote" name="pages">
<option value="1">1 page</option>
<option value="2">2 pages</option>
This works fine in Safari and Chrome, but doesn't work in IE8. In IE8 the change in Select elements doesn't trigger the calculating function.
I researched this issue and got contrary data - some say that Change jQuery event doesn't work in IE8 and some say it does.
I then thought to use the onChange function of JS, but also read that it is not supported by IE8.
Could you help with figuring out the way to do it that works in all browsers.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
根据我的经验,jQuery 中的“更改”事件在 IE8 中确实适用于选择列表,也许您的代码中还有另一个错误导致了该问题?
In my experience the 'change' event in jQuery does work in IE8 for select lists, perhaps there is another bug in your code that is causing the issue?
如果您使用旧版本的 jquery,请尝试此操作
,您可能需要使用“bind”而不是“on”
try this
if you're using an old version of jquery, you might need to use "bind" instead of "on"
尝试改用 $("select option").click() 事件处理程序。
Try using the $("select option").click() event handler instead.