onclick event in select HTML not working in Safari

元气小坏坏 提交于 2019-12-30 14:56:10

问题


I have an ASP.NET dropdown list control with onclick and onchange JavaScript events. Both work in IE, Mozilla, Opera and Chrome, but not in Safari. When I remove the onclick event, onchange suddenly works.

The reason I use onclick is to get the value of the dropdown list before it changes. Is there a way I can do that without using onclick? That is, get the value of the dropdown list before it changes/a new value is selected? I want to do this in JavaScript only.


回答1:


Sometimes you need to add preference to the JavaScript function as "javascript:"; for example:

<select onclick="changeDate()">

should be

<select onclick="javascript:changeDate()">



回答2:


Replacing the onclick event with onfocus solved the problem. I guess Safari doesn't like onclick event on select elements.




回答3:


For me in Chrome, onclick working with second click on select box Where as in FF & IE, its working fine for first click itself.



来源:https://stackoverflow.com/questions/1769374/onclick-event-in-select-html-not-working-in-safari

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!