2012-02-12 116 views
1

在jQuery UI的用戶可將複選框或單選字段按鈕jQuery UI的按鈕 - >http://jqueryui.com/demos/button/#radio的選擇字段

現在,我要爲選擇字段的選項值相同。 這意味着:

<select name="text"> 
<option>Value 1</option> 
<option>Value 2</option> 
<option>Value 3</option> 
<option>Value 4</option> 
</select> 

應轉化爲:

<input type="button" value="Value 1"> 
<input type="button" value="Value 2"> 
<input type="button" value="Value 3"> 
<input type="button" value="Value 4"> 

是否有任何人對我此事的解決方案?

回答

1

是的。例如:

var buttons = ""; 
$("select option").each(function() { 
    buttons += "<input type='button' value='" + this.value + "'/>";  
}); 

$("select").replaceWith(buttons);​ 

Demo.

+0

感謝:-)這是一個正確的答案:-) – htw 2012-02-12 18:01:50