全選: 這裡是用JS實現的:http://www.cnblogs.com/xuyiqing/p/8378221.html 如果使用jQuery則會方便很多: <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>全選和全不選</tit ...
全選:
這裡是用JS實現的:http://www.cnblogs.com/xuyiqing/p/8378221.html
如果使用jQuery則會方便很多:
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>全選和全不選</title> <script type="text/javascript" src="js/jquery-1.8.3.js" ></script> <script> $(function(){ $("#checkAll").click(function(){ //$("tbody input").attr("checked",this.checked); //這種方式對高版本jQuery不適用,下邊方法適用於所有版本 $("tbody input").prop("checked",this.checked); }); }); </script> </head> <body> <table border="1" width="500" height="50" align="center"> <thead> <tr> <th><input type="checkbox" id="checkAll" /></th> <th>編號</th> <th>姓名</th> <th>年齡</th> </tr> </thead> <tbody> <tr> <td><input type="checkbox" name="checkOne" /></td> <td>1</td> <td>張三</td> <td>22</td> </tr> <tr> <td><input type="checkbox" name="checkOne" /></td> <td>2</td> <td>李四</td> <td>25</td> </tr> <tr> <td><input type="checkbox" name="checkOne" /></td> <td>3</td> <td>王五</td> <td>27</td> </tr> <tr> <td><input type="checkbox" name="checkOne" /></td> <td>4</td> <td>趙六</td> <td>29</td> </tr> <tr> <td><input type="checkbox" name="checkOne" /></td> <td>5</td> <td>田七</td> <td>30</td> </tr> <tr> <td><input type="checkbox" name="checkOne" /></td> <td>6</td> <td>汾九</td> <td>20</td> </tr> </tbody> </table> </body> </html>View Code
二級聯動:
這裡是用JS實現的:http://www.cnblogs.com/xuyiqing/p/8378459.html
使用jQuery實現:
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>註冊頁面重新佈局</title> <script type="text/javascript" src="js/jquery-1.8.3.js"></script> <script> $(function() { //2.創建二維數組用於存儲省份和城市 var cities = new Array(3); cities[0] = new Array("武漢市", "黃岡市", "襄陽市", "荊州市"); cities[1] = new Array("長沙市", "郴州市", "株洲市", "岳陽市"); cities[2] = new Array("石家莊市", "邯鄲市", "廊坊市", "保定市"); cities[3] = new Array("鄭州市", "洛陽市", "開封市", "安陽市"); $("#province").change(function() { //10.清除第二個下拉列表的內容 $("#city").empty(); //1.獲取用戶選擇的省份 var val = this.value; //3.遍歷二維數組中的省份 $.each(cities, function(i, n) { //4.判斷用戶選擇的省份和遍歷的省份 if(val == i) { //5.遍歷該省份下的所有城市 $.each(cities[i], function(j, m) { //6.創建城市文本節點 var textNode = document.createTextNode(m); //7.創建option元素節點 var opEle = document.createElement("option"); //8.將城市文本節點添加到option元素節點中去 $(opEle).append(textNode); //9.將option元素節點追加到第二個下拉列表中去 $(opEle).appendTo($("#city")); }); } }); }); }); </script> </head> <body> <div id="content"> <table border="1" align="center" cellpadding="0" cellspacing="0" width="70%" height="70%" bgcolor="white"> <form method="get" action="#" onsubmit="return checkForm()"> <tr> <td colspan="2" align="center"> <font size="5">會員註冊</font> </td> </tr> <tr> <td> 用戶名 </td> <td> <input type="text" name="username" id="username" onfocus="showTips('username','必須以字母開頭')" onblur="check('username','用戶名不能為空')" /><span id="usernamespan"></span> </td> </tr> <tr> <td>密碼</td> <td> <input type="password" name="password" id="password" onfocus="showTips('password','密碼長度不能低於6位!')" onblur="check('password','密碼不能為空!')" /><span id="passwordspan"></span> </td> </tr> <tr> <td>確認密碼</td> <td> <input type="password" name="repassword" /> </td> </tr> <tr> <td>email</td> <td> <input type="text" name="email" id="email" /> </td> </tr> <tr> <td>姓名</td> <td> <input type="text" name="name" /> </td> </tr> <tr> <td>籍貫</td> <td> <select id="province"> <option>--請選擇--</option> <option value="0">湖北</option> <option value="1">湖南</option> <option value="2">河北</option> <option value="3">河南</option> </select> <select id="city"> </select> </td> </tr> <tr> <td>性別</td> <td> <input type="radio" name="sex" value="男" />男 <input type="radio" name="sex" value="女" />女 </td> </tr> <tr> <td>出生日期</td> <td> <input type="text" name="birthday" /> </td> </tr> <tr> <td>驗證碼</td> <td> <input type="text" name="yanzhengma" /> </td> </tr> <tr> <td colspan="2"> <input type="submit" value="註冊" /> </td> </tr> </form> </table> </div> </body> </html>View Code