我正在开发javascript onclick事件,当我调用按钮上的功能点击它不能在IE浏览器上运行(IE-9& IE-8)
代码如下
<input type='image' src="mybutton.jpeg" name="submit" id="button" onclick="return myfunction();" />
我在页面顶部定义了函数,
<script type="text/javascript">
function myfunction()
{
alert("This is testing");
}
</script>
处理所有其他浏览器,例如chrome&amp;火狐但不在IE中。
请帮我解决这个问题。
答案 0 :(得分:1)
更改您的onclick:
onclick="return myfunction();"
到
onsubmit="return myfunction();"
答案 1 :(得分:0)
我不喜欢放“听众”属性。这对我有用:
HTML:
<input type='image' src="" name="submit" id="button" />
JS:
function myfunction() {
alert("This is testing");
}
document.getElementById('button').addEventListener('click', function() {
return myfunction()
} , false);