IE8简单警报失败了吗? [英] IE8 simple alert is failing?

查看:64
本文介绍了IE8简单警报失败了吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么以下代码不能在IE8中运行?

Why isn't the following piece of code working in IE8?

<select>
    <option onclick="javascript: alert('test');">5</option>

相当奇怪 - IE8中没有显示警报。我也没有在左角看到错误图标。当然它适用于FF和Opera。任何想法?

Quite bizarre - no alert is shown in IE8. I do not see the error icon in the left corner as well. Of course it works in FF and Opera. Any ideas?

推荐答案

在<$ c上放置一个 onclick 处理程序$ c>< option> 元素似乎......对我来说很奇怪。您可能希望将其切换到< select> 中更常见的 onchange 事件。你仍然可以从那里做任何你想做的事情,这是你想对选择做任何事情的接受方式。话虽这么说,您可能想尝试删除 javascript:部分内容。只有在链接 href 中执行Javascript时才需要这样做。 onclick 处理程序需要 javascript。

Putting an onclick handler on an <option> element seems.... weird to me. You might want to switch that to the more common onchange event of the <select>. You can still do whatever you want to do from there, and this is the "accepted" way of doing whatever you want to do to the select. That being said, you might want to try removing the javascript: part of it. That is only needed when you are executing Javascript in a link href for example. An onclick handler expects javascript.

这篇关于IE8简单警报失败了吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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