这是 IE8 还是 jQuery 的错误吗?
在 IE8 中不响应 click/contextmenu 事件?
以下是在本地验证的所有代码:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<meta http-equiv="Content-Language" content="en-us" />
<title>International Properties</title>
<script type="text/javascript" src="http://jqueryjs.googlecode.com/files/jquery-1.2.6.min.js"></script>
</head>
<body>
<script type="text/javascript">
$(function(){
$('option').bind('click contextmenu',function(){
alert(1);
});
});
</script>
<select size="2">
<option class="showme" id="article1">test1</option>
<option class="showme" id="article2">test2</option>
</select>
</body>
</html>
编辑
我提供的代码是为了澄清我遇到的问题。
最终我会做类似的事情:
$('option').contextMenu('myMenu1'...
<option>
doesn't respond click/contextmenu events in IE8?
Here is all the code to verify it locally:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<meta http-equiv="Content-Language" content="en-us" />
<title>International Properties</title>
<script type="text/javascript" src="http://jqueryjs.googlecode.com/files/jquery-1.2.6.min.js"></script>
</head>
<body>
<script type="text/javascript">
$(function(){
$('option').bind('click contextmenu',function(){
alert(1);
});
});
</script>
<select size="2">
<option class="showme" id="article1">test1</option>
<option class="showme" id="article2">test2</option>
</select>
</body>
</html>
EDIT
The code I provided is to clarify the issue I met.
Eventually I'll do something like:
$('option').contextMenu('myMenu1'...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
将处理程序绑定到选择,使用 Event.target 获取用户单击的选项。这对我有用:
编辑
我已经在 ie6、ie7 和 ie8 上测试了它 http://ipinfo.info/netrenderer/index.php,使用以下代码。最后一个选项被选中,显示“click() on:article2”。
bind the handler to the select, use Event.target to get at the option the user clicked. this works for me:
edit
i've tested it in ie6, ie7 and ie8 on http://ipinfo.info/netrenderer/index.php, using the following code. the last option comes up selected, displays "click() on: article2".
我认为您需要将事件绑定到 select 而不是选项:
I think you need to bind the events to select instead of option: