IE8 中选择元素和 jQuery CHANGE 事件?

发布于 2024-10-19 06:43:14 字数 796 浏览 1 评论 0原文

我的网站上有一个小脚本,它根据 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

不及他 2024-10-26 06:43:14

根据我的经验,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?

日暮斜阳 2024-10-26 06:43:14

如果您使用旧版本的 jquery,请尝试此操作

$("#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
});

,您可能需要使用“bind”而不是“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
});

try this

$("#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
});

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
});
故事还在继续 2024-10-26 06:43:14

尝试改用 $("select option").click() 事件处理程序。

Try using the $("select option").click() event handler instead.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文