不能调用Javascript函数 [英] Cannot call Javascript function
本文介绍了不能调用Javascript函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
请注意以下示例代码:
< html>
< head>
< script type =text / javascript>
函数myfun()
{
alert('hi');
}
< / script>
< / head>
< body>
< h1>你好< / h1>
< input type =buttonvalue =MyButtononClick =myfun()/>
< / body>
< / html>
当我使用php运行这个时,当我点击按钮时,警告框不会上来。但是,如果我写 onclick =alert(hi')
,它可以正常工作。可能是什么原因?
解决方案
< html>
< body>
< h1>你好< / h1>
< input type =buttonvalue =MyButtononClick =alert('hi')/>
< / body>
< / html>
缺少代码中的'...
please look at the following sample code:
<html>
<head>
<script type="text/javascript">
function myfun()
{
alert('hi');
}
</script>
</head>
<body>
<h1> Hello </h1>
<input type="button" value="MyButton" onClick="myfun()"/>
</body>
</html>
When I run this using php, and when I click on the button, the alert box doesn't come up. However, if I write onclick="alert(hi')"
it works fine. What might be the reason?
解决方案
<html>
<body>
<h1> Hello </h1>
<input type="button" value="MyButton" onClick="alert('hi')"/>
</body>
</html>
Missing a ' in your code...
这篇关于不能调用Javascript函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文