checkbox選中事件


在前端中,往往需要根據后台數據的返回選中多選框。可以根據后台返回的數據轉化為數組,然后又val([數組])進行選中。

例子:

html代碼:

 1 <!DOCTYPE html>
 2   <html>
 3   <head>
 4   <title>多選框選中狀態</title>
 5   <script type="text/javascript" src="jquery.js"></script>
 6   </head>
 7   <body>
 8   <input type="checkbox" name="" value="1" class="checkxh"><label>1</label>
 9   <input type="checkbox" name="" value="2" class="checkxh"><label>1</label>
10   <input type="checkbox" name="" value="3" class="checkxh"><label>1</label>
11   <input type="checkbox" name="" value="4" class="checkxh"><label>1</label>
12   <input type="checkbox" name="" value="5" class="checkxh"><label>1</label>
13   </body>
14   </html>

javascript代碼:

1 <script type="text/javascript">
2     $('.checkxh').val([1,2,5]);
3   </script>

得到的效果:

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM