锋利的jQuery-3--用js给多选的checkbox或者select赋值

单选的select:

<select id="single">
  <option>Single</option>
  <option>Single2</option>
</select>
$("#single").val("Single2");

多选的select:

<select id="multiple" multiple="multiple">
  <option selected="selected">Multiple</option>
  <option>Multiple2</option>
  <option selected="selected">Multiple3</option>
</select><br/>

 

$("#multiple").val(["Multiple2", "Multiple3"]);  //注意是数组形式里边

checkbox和radio:

<input type="checkbox" value="check1"/> check1
<input type="checkbox" value="check2"/> check2
<input type="radio" value="radio1"/> radio1
<input type="radio" value="radio2"/> radio2
$("input").val(["check2", "radio1"]);  //可以同时选两种

 

posted @ 2014-10-24 17:40  leezhxing  阅读(542)  评论(0编辑  收藏  举报