單選框、複選框的值獲取與設置

1.  樣式:<div>
              <h4>是否關聯模型:
                 <input type="checkbox" name="tvod" class="" value="1">關聯
              </h4> 
          </div>ios

     取值:var value =  $('input:checkbox[name="tvod"]:checked').val();get

     設值:$('input:checkbox[name="tvod"]').val([info.isLinkModel]);input

 

2  樣式:<div>
             <h4>是否少兒頻道:&nbsp;&nbsp;
                <label class="label-radios">
                   <input type="radio" name="childChannel" value="1">是&nbsp;&nbsp;
                   <input type="radio" name="childChannel" checked="checked" value="0">否
                </label>
             </h4> 
          </div>io

     取值:var value =  $('input[name="childChannel"]:checked').val();function

     設值:$('input[name="childChannel"][value="' + data.is_children + '"]').attr('checked','true');class

 

3   樣式:<div>
             <h4>選擇頻道:&nbsp;&nbsp;
                <label class="label-radios">
                   <input type="checkbox" name="channel" class="mail-checkbox" value="1">電影&nbsp;&nbsp;
                   <input type="checkbox" name="channel" class="mail-checkbox" value="0">電視劇
                </label>
             </h4> 
          </div>List

     取值:var selectInfoList = new Array();
          var keys = $('input:checkbox[name="channel"]:checked').map(function(index,elem) {
         return $(elem).val();
       }).get();
       for (var key in keys){
         selectInfoList[selectInfoList.length] = searchInfoList[parseInt(keys[key])];
       }select

     設值:map

相關文章
相關標籤/搜索