Javascript函数在IE浏览器中不起作用

时间:2013-03-01 13:03:36

标签: javascript html5 internet-explorer css3 browser

我正在开发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中。

请帮我解决这个问题。

2 个答案:

答案 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);