js中的一个checkbox的问题-------第二日用上(Array.prototype.slice.call)
来源:互联网 发布:淘宝客服骂人不带脏字 编辑:程序博客网 时间:2024/04/29 10:55
这是源代码
<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> <title>无标题文档</title> </head> <body> <form> 请选择你爱好:<br> <input type="checkbox" name="hobby" id="hobby1"> 音乐 <input type="checkbox" name="hobby" id="hobby2"> 登山 <input type="checkbox" name="hobby" id="hobby3"> 游泳 <input type="checkbox" name="hobby" id="hobby4"> 阅读 <input type="checkbox" name="hobby" id="hobby5"> 打球 <input type="checkbox" name="hobby" id="hobby6"> 跑步 <br> <input type="button" value = "全选" onclick = "checkall();"> <input type="button" value = "全不选" onclick = "clearall();"> <p>请输入您要选择爱好的序号,序号为1-6:</p> <input id="wb" name="wb" type="text" > <input name="ok" type="button" value="确定" onclick = "checkone();"> </form> <script type="text/javascript"> function checkall(){ var hobby = document.getElementsByTagName("input"); for(var i=0;i<6;i++){ if(hobby[i].type="checkbox"){hobby[i].checked=true} } // 任务1 } function clearall(){ var hobby = document.getElementsByName("hobby"); for(var n=0;n<6;n++){ if(hobby[n].type="chekbox"){ ;hobby[n].checked=false;} } // 任务2 } function checkone(){ var j=document.getElementById("wb").value; var hobby=document.getElementsByName("hobby");if(parseInt(j)>=1&&parseInt(j)<=6){hobby[parseInt(j)-1].checked=true;}else{alert("你输入的数字不在范围之内");} // 任务3 } </script> </body></html>
可以看出在浏览器中显示为
意为点击全选选中6个复选框,点击全不选6个复选框复位,但当我点击全不选后成了如图所示,发现6个复选框变为了6个text类型的。,,现没看出哪里的问题,待更新,,,,二〇一七年十一月九日 00:01:24
-----------------------------------------------------------------------------------------------------------------------
二〇一七年十一月九日 12:59:36
/*function clearall(){ var hobby = document.getElementsByName("hobby"); for(var n=0;n<6;n++){ if(hobby[n].type="chekbox"){ ;hobby[n].checked=false;} } // 任务2 }*/function clearall() {var hobby=document.getElementsByName("hobby");var hobby_arr=Array.prototype.slice.call(hobby);hobby_arr.forEach(function(v){v.checked=false;})}
把昨天的注释掉,用上Array.prototype.slice.call()方法,将得到的hobby转换为真数组再进行逐个操作,发现运行后解决问题,但是原理还是暂不得而知。。。。
阅读全文
0 0
- js中的一个checkbox的问题-------第二日用上(Array.prototype.slice.call)
- Array.prototype.slice.call()
- JS 有趣的应用 : Array.prototype.slice.call(arguments,0)
- JS 有趣的应用 :Array.prototype.slice.call(arguments,0)
- Array.prototype.slice.call
- Array.prototype.slice.call
- Array.prototype.slice.call
- Array.prototype.slice.call
- Array.prototype.slice.call
- Array.prototype.slice.call
- 浅谈javascript的Array.prototype.slice.call
- 浅谈javascript的Array.prototype.slice.call
- javascript的Array.prototype.slice.call
- 什么是Array.prototype.slice.call
- Array.prototype.slice.call(arguments)
- Array.prototype.slice.call(arguments)
- Array.prototype.slice.call(arguments)
- Array.prototype.slice.call(arguments)
- [Introducing Ethereum and Solidity]以太坊和solidity介绍----第一章-连接区块链知识的断点
- z-tree树的用法
- Y
- 在idea上用SparkStreaming实现从远程socket读取数据并完成Wordcount
- 不在被虐中成长就在被虐中死亡
- js中的一个checkbox的问题-------第二日用上(Array.prototype.slice.call)
- 自己总结的USB数据结构及其描述符
- Java集合之Hashtable源码解析
- Oracle之高水位(HWM:high water mark)
- 彻底搞懂C#之Yield Return语法的作用和好处
- bable表格的应用
- 实验一(二) DFA识别字符串
- 在 CentOS7 上安装 Zookeeper-3.4.9 服务
- table制作表表格应用