最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

html - Call javascript on checkbox onclick - Stack Overflow

programmeradmin3浏览0评论

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?

<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

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?

<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

Share Improve this question asked Oct 5, 2010 at 8:46 DijkstraDijkstra 2,5303 gold badges22 silver badges35 bronze badges 0
Add a comment  | 

2 Answers 2

Reset to default 13

Change the function name [e.g. selectFun]. select seems to be reserved keyword

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.

发布评论

评论列表(0)

  1. 暂无评论