我試圖用jQuery將選擇列表添加到div表中,完成後,我想選擇列表的特定選項,我試圖這樣:Jquery:克隆選擇列表並選擇一個選項的值
// my hidden option list
<div style="display:none;">
<select class="option_list">
<option value="male">Male</option>
<option value="female">Female</option>
<option value="none">Unknown</option>
</select>
</div>
<div id="my_table">
<div>
<div>John</div>
<div>25</div>
<div></div>
</div>
<div>
<div>Emy</div>
<div>22</div>
<div></div>
</div>
<div>
<div>Sarah</div>
<div>28</div>
<div></div>
</div>
</div>
// $(".option_list") is hidden in HTML page, I clone and append it to my div table row
$(".option_list")
.clone()
.appendTo ("#my_table > div > div:last-child")
.attr ("name", "a_dynamic_name_for_php_form")
.find ("option[value=none]").selected = true;
感謝您的幫助,它的工作原理 – vitto 2010-01-24 13:22:56