通過javascript擷取被勾選的checkbox解決方案

來源:互聯網
上載者:User

標籤:

思路:

用javascript的dom操作擷取節點,並擷取其屬性,得到要擷取的類的id的String,發給後台,截取String,獲得該類的List。

需要注意的是:

不知道為什麼getIlementById("id").getAttribute("value")擷取不到,value屬性。所以選擇getIlementById("id").getAttribute("title")來擷取寫在title中的屬性。

 

具體實現:

list是後台傳來的xmdj實體類的List。

<form>    <label>          項目列表:    </label>        <c:forEach items = "${list}"   var = "xm" varStatus = "status">               <c:if test = "${status.count%2 eq 0}"><p></p></c:if>               <input type="checkbox" id = "${status.index}"  title = "${xm.id}">${xm.name}</input>         </c:forEach>       <input id = "btnSubmit" type ="button" value = "儲存"/></form>

 

js代碼:

//全域設定ajax為同步$.ajaxSetup({   async:false)};$(document).ready(function(){       $("#btnSubmit").click(function(){                 var xmNum;                  //獲得項目數                 $.getJSON("${ctx}/sys/show/getXmLength",fuction(data){        xmNum = data;  });var param = "";for(var i = 0; i < xmNum; i++){   if(document.getElementById(i.toString()).checked){        param += document.getElementById(i.toString()).getAttribute("title")+",";    }//把擷取的String發給後台,由後台截取String獲得id的List$.post……}  

 

通過javascript擷取被勾選的checkbox解決方案

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.