HTML5按钮ONCLICK功能



我的代码非常简单,因为我只是学会使用JavaScript。

我正在尝试使HTML5 button元素单击时执行简单的警报功能。但是,使用以下代码,该按钮什么都不做。

     function theFunction(){
            alert("Hi there");
        }
 <button type="button" onlick="theFunction()">Button</button>

; onlick;" onclick"Speel错误的支票并正确

function theFunction(){
            alert("Hi there");
        }
<button type="button" OnClick="theFunction()">Button</button>

它是 onclick=func_nameonlick

function theFunction(){
            alert("Hi there");
        }
<button type="button" onclick="theFunction()">Button</button>

您想念c

<button type="button" onlick="theFunction()">Button</button>
                     //^------------------ change to onclick

有一个小错字。更改为 c lick

只需将 onlick更改为 onclick

 function theFunction(){
            alert("Hi there");
        }
 <button type="button" onclick="theFunction()">Button</button>

应该像这样:

     function theFunction(){
            alert("Hi there");
        }
 <button onclick="theFunction()">Click me</button>

您错过了OnClick中的某些角色。

function theFunction(){
     alert("Hi there");
}
 <button type="button" onClick="theFunction()">Button</button>

您错误地将Onlick写给了Onlick。这是ES6示例代码。

<button type="button" onclick="clickFunction()">ClickME</button>
let clicka = clickFunction(() => 
 alert("Success")
);

最新更新