亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

以下js應該怎樣封裝成fun(id,name){}

以下js應該怎樣封裝成fun(id,name){}

qq_sU_4 2016-07-21 14:59:03
<!DOCTYPE?html> <html?lang="en"> <head> ????<meta?charset="UTF-8"> ????<title>Title</title> ????<script?src="jquery.min.js"></script> </head> <body> <table?id="setPermission"?class="table?marginTop_30"> ????<tr> ????????<td?colspan="5"> ????????????<span?class="font_bold?margin_X10">角色管理</span> ????????????<input?type="checkbox"?id="selectAllTerm"> ????????????<label?for="selectAllTerm">全選</label> ????????</td> ????</tr> ????<tr?id="termRow"> ????????<td> ????????????<input?type="checkbox"?name="chTerm"?id="dd"> ????????????<label>查看學期列表</label> ????????</td> ????????<td> ????????????<input?type="checkbox"?name="chTerm"> ????????????<label>添加學期</label> ????????</td> ????????<td> ????????????<input?type="checkbox"?name="chTerm"> ????????????<label>修改學期</label> ????????</td> ????????<td> ????????????<input?type="checkbox"?name="chTerm"> ????????????<label>刪除學期</label> ????????</td> ????????<td> ????????????<input?type="checkbox"?name="chTerm"> ????????????<label>停用/啟用學期</label> ????????</td> ????</tr> ????<tr> ????????<td?colspan="5"> ????????????<span?class="font_bold?margin_X10">專業管理</span> ????????????<input?type="checkbox"?id="selectAllSpecialty"> ????????????<label?for="selectAllSpecialty">全選</label> ????????</td> ????</tr> ????<tr?id="specialtyRow"> ????????<td> ????????????<input?type="checkbox"?name="chAllSpecialty"> ????????????<label>查看專業列表</label> ????????</td> ????????<td> ????????????<input?type="checkbox"?name="chAllSpecialty"> ????????????<label>添加專業</label> ????????</td> ????????<td> ????????????<input?type="checkbox"?name="chAllSpecialty"> ????????????<label>修改專業</label> ????????</td> ????????<td> ????????????<input?type="checkbox"?name="chAllSpecialty"> ????????????<label>刪除專業</label> ????????</td> ????????<td> ????????????<input?type="checkbox"?name="chAllSpecialty"> ????????????<label>停用/啟用專業</label> ????????</td> ????</tr> </table> <script> ?????var?checkList=$("input[name='chTerm']"); ????function?selectAll?(id)?{ ????????$(id).click(function?()?{ ????????????checkList.prop("checked",?$(id).prop("checked")); ????????????hasAll(); ????????}); ????}; ????function?hasAll(){ ????????var?chknum?=?checkList.length; ????????var?Count=0; ????????for(var?i=0;i<chknum;i++){ ????????????if(checkList[i].checked){ ????????????????Count++; ????????????} ????????} ????????console.log(Count); ????????if(chknum==Count){//全選 ????????????$("#selectAllTerm").prop("checked",true); ????????}else{//不全選 ????????????$("#selectAllTerm").prop("checked",false); ????????} ????} ????selectAll(selectAllTerm); ????selectAll(selectAllSpecialty); $(function(){ ????$("input[name='chTerm']").each(function(){ ????????$(this).click(function(){ ????????????hasAll(); ????????}) ????}) }) </script> </body> </html>
查看完整描述

2 回答

?
寶慕林2233867

TA貢獻10條經驗 獲得超1個贊

封裝函數主要就是寫一個function,函數體寫在函數里面就形成函數了,把經常改的東西變為參數就好了,然后最后用的時候調用一次就好了。

查看完整回答
反對 回復 2016-07-26
  • 2 回答
  • 0 關注
  • 1638 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號