js取得gridview中獲取checkbox選中的值--單選

taogchan發表於2012-12-21
 
       var ClickNum = 0; //判斷同一checkbox連續點選次數
       var PreCheckboxID = ""; //記錄點選checkbox的ID
       //listId為控制checkbox的範圍
       //SelectRadio是點選checkbox自己
       function SelectRadio(listId, SelectRadio) {
           ///判斷是否連擊同一個checkbox
           if (PreCheckboxID == SelectRadio.id) {
               ClickNum = ClickNum + 1;
           }
           else {
               PreCheckboxID = SelectRadio.id;
               ClickNum = 0;
           }
           //找到控制範圍
           var GridViewtableSearchList = document.getElementById(listId);
           //找到控制範圍下所有input
           var bjs = GridViewtableSearchList.getElementsByTagName("input");
           //找到控制範圍下所有checkbox並都變為false
           for (var i = 0; i < objs.length; i++) {
               if (objs[i].type.toLowerCase() == "checkbox")
                   objs[i].checked = false;
           }
           var SelectRadioID = SelectRadio.id;
           //如果連擊次數為奇次checked為true偶次為false
           if (ClickNum % 2 != 1) {
               document.getElementById(SelectRadioID).checked = true;
           }
           else {
               document.getElementById(SelectRadioID).checked = false;
           }
       }

       function SED(listId) {
           var GridViewtableSearchList = document.getElementById(listId);
           for (i = 1; i < GridViewtableSearchList.rows.length; i++) {
               var cb = GridViewtableSearchList.rows(i).cells(0).children(0);
               if (cb.checked) {
                   document.getElementById("SheetTextBox1").value = GridViewtableSearchList.rows(i).cells(2).innerText;
                   document.getElementById("SheetTextBox2").value = GridViewtableSearchList.rows(i).cells(3).innerText;
                   document.getElementById("SheetTextBox3").value = GridViewtableSearchList.rows(i).cells(4).innerText;
               }
           }

        }
 
 
 

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/22392018/viewspace-751503/,如需轉載,請註明出處,否則將追究法律責任。

相關文章