<button onclick="hello()">Hello</button>
<script>
function hello() {
alert('Hello');
}
</script>
这是我的代码。但它不起作用。当我单击按钮时,没有任何 react 。
最佳答案
请注意遇到此问题的其他开发人员,如果您使用保留的方法名称,例如clear
.
<!DOCTYPE html>
<html>
<body>
<button onclick="clear()">Clear</button>
<button onclick="clear2()">Clear2</button>
<script>
function clear() {
alert('clear');
}
function clear2() {
alert('clear2');
}
</script>
</body>
</html>
关于JavaScript按钮onclick不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42530261/