最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - IE8 simple alert is failing? - Stack Overflow

programmeradmin1浏览0评论

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

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

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?

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

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

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?

Share Improve this question asked May 10, 2009 at 18:44 PetrunovPetrunov 7741 gold badge8 silver badges18 bronze badges
Add a comment  | 

3 Answers 3

Reset to default 17

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.

Have you tried just:

onclick="alert('test');"

Pretty sure you don't need the javascript: prefix.

All versions of IE (6,7,8) do not support ANY event handlers on the option elements.

This is a (fairly) well known bug that the IE team has indicated they are in no rush to fix. :-(

Then again Opera, Safari & Chrome all have limited or no support for event handlers on options too.

Lack of events on options: bug 280

(related) Lack of styles on options: bug 281

It should be noted that "Edge" (think IE12 on Windows 10) is currently showing that this issue is fixed in preview releases.

发布评论

评论列表(0)

  1. 暂无评论