无法调用Javascript函数

时间:2011-03-26 13:12:11

标签: javascript html

请查看以下示例代码:

<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>  

当我使用php运行时,当我点击按钮时,警报框不会出现。但是,如果我写onclick="alert(hi')"它可以正常工作。可能是什么原因?

1 个答案:

答案 0 :(得分:0)

<html>

   <body>
        <h1> Hello </h1>
    <input type="button" value="MyButton" onClick="alert('hi')"/>
   </body>
</html>  

在代码中遗漏了一个'

相关问题