3 回答

TA貢獻(xiàn)1786條經(jīng)驗 獲得超13個贊
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<button id = "historyBtn" onclick="allMessage()">History</button>
</body>
<script>
window.onload = limit_message();
function allMessage (){
alert ('In all messages - historyBtn clicked!');
}
function limit_message (){
alert ('limit_message - onload');
}
</script>
</html>

TA貢獻(xiàn)1810條經(jīng)驗 獲得超4個贊
function hello(ishistory) {
if (ishistory) {
console.log("History")
}else{
console.log("Limit")
}
}
<button onclick="hello(true)">history</button>
<button onclick="hello(false)">Limit</button>
只需傳遞一個標(biāo)志即可在單擊按鈕時運行,如下所示。

TA貢獻(xiàn)1829條經(jīng)驗 獲得超7個贊
試試這個,首先獲取按鈕元素,然后分配一個 eventListener 并記錄單擊事件:
let history = document.getElementById('historyBtn');
history.addEventListener('click', function(e){
console.log(e)
})
添加回答
舉報