在IE8中选择元素和jQuery CHANGE事件? [英] Select element and jQuery CHANGE event in IE8?

查看:442
本文介绍了在IE8中选择元素和jQuery CHANGE事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的网站上有一个小脚本,该脚本根据4种不同的Select元素中选择的选项来计算报价.价格报价会写入div,并且每次所选选项发生变化时都会更新.

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.

这是此页面的链接: http://www.justaddsolutions.com/justaddwebsite/prices /

每次Select元素发生更改时,我都会使用jQuery CHANGE事件处理程序来触发计算函数,如下所示:

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);

这是我附带的HTML代码:

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>

这在Safari和Chrome中正常运行,但在IE8中不起作用.在IE8中,Select元素的更改不会触发计算功能.

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.

我研究了此问题,并获得了相反的数据-有人说Change jQuery事件在IE8中不起作用,而有人说可以.

I researched this issue and got contrary data - some say that Change jQuery event doesn't work in IE8 and some say it does.

然后我想到了使用JS的onChange函数,但同时也看到IE8不支持它.

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.

推荐答案

尝试一下

$("#pages").on("keyup change", function () {
    // let's make sure the event is not the problem , could be a problem with price_quoter? 
    alert("yay!! pages was changed");
    // call your function
    price_quoter();
    // do stuff here
});

如果您使用的是旧版的jquery,则可能需要使用"bind"而不是"on"

if you're using an old version of jquery, you might need to use "bind" instead of "on"

$("#pages").bind("keyup change", function () {
    // let's make sure the event is not the problem , could be a problem with price_quoter? 
    alert("yay!! pages was changed");
    // call your function
    price_quoter();
    // do stuff here
});

这篇关于在IE8中选择元素和jQuery CHANGE事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆