2011-09-03 47 views
1

,我有以下的下拉菜單下拉菜單中的HTML表單個性化

<p> 
<label for='Select a Category '>Select a Category<font color="red"><strong>*</strong></font>: </label></p> 
<p><div id='contactform_category_errorloc' class='err'></div> 

    <select name="category" class="input"> 
    <option value="0" selected="selected"> 
     [choose yours] 
    </option> 
    <option value="Arts and entertainment">Arts and entertainment</option> 
    <option value="Automotive">Automotive</option> 
    <option value="Business">Business</option> 
    <option value="Computers">Computers</option> 
    <option value="Games">Games</option> 
    <option value="Health">Health</option> 
    <option value="Internet">Internet</option> 
    <option value="News and Media">News and Media</option> 
    <option value="Recreation">Recreation</option> 
    <option value="Reference">Reference</option> 
    <option value="Shopping">Shopping</option> 
    <option value="Sports">Sports</option> 
    <option value="World">World</option> 
    </select> 
</p> 

我想在降與增值下拉菜單選項的代碼的一部分:「自定義」,當我選擇此選項出現只是在字段空白下作爲輸入文本,我可以添加我的個性化文本,這樣我可以插入個性化的類別 這是可能的嗎?

+0

可能的複製 - [http://stackoverflow.com/questions/264640/how-can-i-create-an-editable-dropdownlist-in-html](http: //堆棧溢出/我的問題/ 264640/how-can-i-create-an-editable-dropdownlist-in-html) – Will

回答

1

也許你的意思是這樣:http://jsbin.com/ubihuw/edit#javascript,html 所以在PHP或東西,你可以檢查那麼「my_own_text」現場......不知道你究竟會做;)

JS:

$('.input').change(function() 
{ 
    if($(this).attr('value') == "0") { 
    $('#choose_own_text').append('<input type="text" id="my_own_text" name="my_own_text" value="Please type in .." />'); 
    } else { 
    $('#choose_own_text').empty(); 
    } 
}); 

你的代碼...

<p><div id='contactform_category_errorloc' class='err'></div> 

    <select name="category" class="input"> 
    <option value="0" selected="selected"> 
     [choose yours] 
    </option> 
    <option value="Arts and entertainment">Arts and entertainment</option> 
    <option value="Automotive">Automotive</option> 
    <option value="Business">Business</option> 
    <option value="Computers">Computers</option> 
    <option value="Games">Games</option> 
    <option value="Health">Health</option> 
    <option value="Internet">Internet</option> 
    <option value="News and Media">News and Media</option> 
    <option value="Recreation">Recreation</option> 
    <option value="Reference">Reference</option> 
    <option value="Shopping">Shopping</option> 
    <option value="Sports">Sports</option> 
    <option value="World">World</option> 
    </select> 
    <div id="choose_own_text"></div> 
</p> 
+0

好的,謝謝這就是我想要的 – grigione

+0

很好,我可以幫你! – spotlr