爲什麼不能正常工作?無法通過onclick屬性調用函數
HTML:
<html>
<head>
<title>test</title>
</head>
<body>
<button onclick="test21()">test</button>
</body>
</html>
的javascript:
function test21(){
console.log("yey");
}
爲什麼不能正常工作?無法通過onclick屬性調用函數
HTML:
<html>
<head>
<title>test</title>
</head>
<body>
<button onclick="test21()">test</button>
</body>
</html>
的javascript:
function test21(){
console.log("yey");
}
您可以創建調用這兩個的單一功能,然後在事件中使用它。
function myFunction(){
pay();
cls();
}
,然後爲按鈕:
<input id="btn" type="button" value="click" onclick="myFunction();"/>
這工作正常。這是一個JSBin來證明它。
http://jsbin.com/luxesazibi/edit?html,output
更可能你沒有在你的HTML載入你的腳本。你在哪裏把你的JavaScript?
您沒有在html文件中包含腳本。
<html>
<head>
<title>test</title>
<script>
function test21(){
console.log("yey");
}
</script>
</head>
<body>
<button onclick="test21()">test</button>
</body>
</html>
上面的代碼片段將會運行得很好。
使用檢查器(ctrl + shift + I)啓動控制檯並單擊按鈕以獲得結果。
檢查您是否正確包含了js https://plnkr.co/edit/Q0NnFQoWL5kEp2BsglrT?p=preview – Karim