jquery实现全选、全不选、反选、获取选中的所有值总结

我们的页面上有一个歌曲列表,列出多行歌曲名称,并匹配复选框供用户选择,并且在列表下方有一排操作按钮。

<!doctype html> <html> <head> <meta charset="UTF-8"> <title>checkbox2</title> <style> li { list-style:none; } </style> <script src="js/jquery-1.7.2.min.js"></script> <!-- 务必要引用jquery库文件 --> </head> <body> <ul id="list"> <li><label><input type="checkbox" value="1"> 1.如梦一场</label></li> <li><label><input type="checkbox" value="2"> 2.海阔天空</label></li> <li><label><input type="checkbox" value="3"> 3.Let It go</label></li> <li><label><input type="checkbox" value="4"> 4.不再犹豫</label></li> <li><label><input type="checkbox" value="5"> 5.光辉岁月</label></li> <li><label><input type="checkbox" value="6"> 6.泡沫</label></li> </ul> <input type="checkbox" id="all"> <input type="button" value="全选" class="btn" id="selectAll"> <input type="button" value="全不选" class="btn" id="unSelect"> <input type="button" value="反选" class="btn" id="reverse"> <input type="button" value="获得选中的所有值" class="btn" id="getValue"> </body> </html>

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/zwzdws.html