在复选框 onclick 上调用 javascript
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3862098/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Call javascript on checkbox onclick
提问by Dijkstra
I don't understand what I'm doing wrong here. I just want my function to be called when I click the checkbox. Replacing the function call with alert()
works, am I referencing my function incorrectly?
我不明白我在这里做错了什么。我只想在单击复选框时调用我的函数。用alert()
作品替换函数调用,我是否错误地引用了我的函数?
<html>
<head></head>
<body>
<script type="text/javascript">
function select(a){
document.getElementById("myDiv").innerHTML=""+a;
}
</script>
<input type="checkbox" onclick="select(1)">
<div id="myDiv">hi</div>
</body>
</html>
Thanks
谢谢
回答by Chinmayee G
Change the function name [e.g. selectFun]. select
seems to be reserved keyword
更改函数名称 [例如 selectFun]。select
似乎是保留关键字
回答by Kevin D
This puzzled me as it looked ok to me too, So ran through the usual tests, eventually tried changing the function name and that worked fine.
这让我感到困惑,因为它对我来说看起来也不错,所以运行了通常的测试,最终尝试更改函数名称并且效果很好。