1. 程式人生 > >編輯的時候給select,radio傳值選中

編輯的時候給select,radio傳值選中

<select id="selectType">
   <option value="1">1</option>
   <option value="2">2</option>
    <option value="3">3</option>
</select>
var type = "3";
$("#selectType").val(type);

<div>  
   <input type ="radio" name="rating" value="1">1  
   <input type ="radio" name="rating" value="2">2  
   <input type ="radio" name="rating" value="3">3  
   <input type ="radio" name="rating" value="4">4  
</div>  

$("input[name='rating'][value=2]").attr("checked",true);