简体   繁体   English

无法调用Javascript函数

[英]Cannot call Javascript function

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. 当我使用php运行此程序时,并且单击按钮时,警告框不会出现。 However, if I write onclick="alert(hi')" it works fine. 但是,如果我编写onclick="alert(hi')"则可以正常工作。 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... 您的代码中缺少'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM