3 回答

TA贡献1786条经验 获得超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贡献1810条经验 获得超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>
只需传递一个标志即可在单击按钮时运行,如下所示。

TA贡献1829条经验 获得超7个赞
试试这个,首先获取按钮元素,然后分配一个 eventListener 并记录单击事件:
let history = document.getElementById('historyBtn');
history.addEventListener('click', function(e){
console.log(e)
})
添加回答
举报