Jquery - IE6 中 Select dropdown 上的单击事件问题

发布于 2024-08-05 19:48:48 字数 483 浏览 2 评论 0原文

我的 jquery 函数有问题。它适用于 FF,但不适用于 IE 6。我希望在单击选择下拉列表中的任何选项时触发该函数。这是我的功能的开始:

$('#titleSelect option').click( function() {    
    alert("title clicked");
    ......
});

这是我的下拉列表:

<select id="titleSelect">
<option></option>
<option>1</option>
<option>2</option>
<option>3</option>
</select>

所以在 FF 中,警报被触发,但在 IE 中却没有。 IE 在识别选择上的单击事件时是否存在任何问题,如果是,有什么解决办法吗?

I am having an issue with a jquery function. It works in FF but not in IE 6. I want the function to be triggered when any option inside a select drop down is clicked. Here is the start of my funcation:

$('#titleSelect option').click( function() {    
    alert("title clicked");
    ......
});

Here is my drop down list:

<select id="titleSelect">
<option></option>
<option>1</option>
<option>2</option>
<option>3</option>
</select>

So in FF, the alert is triggered but in IE it is not. Is there any sort of an issue with IE recognizing the click event on a select and if so is there any way around it.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

抱猫软卧 2024-08-12 19:48:48

为什么不使用 onChange 事件?例如:

$('#titleSelect').change( function() {    
alert("title "+$(this).val()+" clicked");
......
});

您可以在这里找到 jQuery 更改事件文档:

http://docs.jquery.com /事件/更改#fn

why you don't use the onChange event? like:

$('#titleSelect').change( function() {    
alert("title "+$(this).val()+" clicked");
......
});

the jQuery change-event documentation you can find here:

http://docs.jquery.com/Events/change#fn

你是我的挚爱i 2024-08-12 19:48:48

如果您查看此页面,请转到底部的“适用于”部分,您可以看到该选项元素不在列表中。

http://msdn.microsoft.com/en- us/library/ms536913%28VS.85%29.aspx

如果您确实想要选项元素上的事件,请查看此页面上的事件(单击表中的事件一词):
http://msdn.microsoft.com/en -us/library/ms535877%28VS.85%29.aspx#

否则,只需对 select 元素上的 onchange 事件做出反应,您就会知道什么时候发生了更改,但是,这意味着如果他们单击已选择的事件则不会触发任何事件。

If you look at this page, go to the bottom, the Applies To section, and you can see that the option element is not in the list.

http://msdn.microsoft.com/en-us/library/ms536913%28VS.85%29.aspx

If you really want an event on the option element then look at the events on this page (click on the word events in the table):
http://msdn.microsoft.com/en-us/library/ms535877%28VS.85%29.aspx#

Otherwise, just react to the onchange event on the select element and you will know when something is changed, but, that means that if they click on the event that was already selected then no event will fire.

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