jquery chrome select change / click not working;在IE / FF中工作 [英] jquery chrome select change/click not working; works in IE/FF

查看:95
本文介绍了jquery chrome select change / click not working;在IE / FF中工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的选择列表,当我点击其中一个选项时,会在消息中显示选定的选项。在IE和FF中一切都按预期工作,但在Chrome中无法正常工作。这是我的HTML:

I have a simple select list that when I click on one of the options displays the selected option in a message. Everything works as expected in IE and FF but not in Chrome. Here is my HTML:

<select id="selectlist" class="select_list" size="10" title="Choose an item to load">
  <option value="1">Item 1</option>
  <option value="2">Item 2</option>
  <option value="3">Item 3</option>
  <option value="4">Item 4</option>
  <option value="5">Item 5</option>
</select> 

以下是我的jQuery:

And here is my jQuery:

$(function(){
  $("#selectlist").click(function(event){
    alert("Click event on Select has occurred!");
    $("option:selected", $(this)).each(function(){
      ...more code here...
    });
  });
});

在IE和FF中,只要点击一个选项但不在Chrome中就会显示警报。我使用了 .change 而不是 .click ,其结果完全相同。
任何帮助都将得到真正的赞赏。

In IE and FF the alert displays whenever an option is clicked but not in Chrome. I have used .change rather than .click with exactly the same results. Any help would be truly appreciated.

更新!

经过进一步的研究和测试,我认为问题不在于选择标记,而是与jquery对话框相关。我在 http://jsfiddle.net/chuckl/6Gh78/3/重现了这个问题。点击Load按钮来产生对话窗口。在FF中,您可以点击列表中的一个项目,它将被选中, p 标签更新,并且会出现一个警告框。在Chrome浏览器中,您只能看到警报框。

After further research and testing I believe the problem is not with the select tag but is related to the jquery dialog. I have created a test case at http://jsfiddle.net/chuckl/6Gh78/3/ that reproduces the problem. Click on the Load button to produce the dialog window. In FF you can click on an item in the list and it will be selected, the p tag updated, and an alert box will appear. In Chrome all you get is the alert box.

推荐答案

我发现以下工作适用于我 - 而不是单击时使用,使用更改例如:

I found that the following worked for me - instead on using on click, use on change e.g.:

 jQuery('#elemen select').on('change',  (function() {

       //your code here

}));

这篇关于jquery chrome select change / click not working;在IE / FF中工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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