簡體   English   中英

用於創建文本字段的下拉菜單

[英]dropdown menu to create text field

我花了大約一兩個小時試圖找出當從下拉列表中選擇某個值時如何使用JavaScript創建文本字段。

這是下拉菜單的代碼,如果有任何幫助的話。 我本來試圖編寫代碼來做這件事,但我仍然不熟悉如何編寫JavaScript代碼

<select name="claim">
    <option value="">Select a Claim</option>
    <option value="Insurance">Insurance</option> // this option I want when selected to create a text field
    <option value="Warranty">Warranty</option>
</select>

試試這個希望它有所幫助

   <div id="area">
         <select id="claim" name="claim">
            <option value="">Select a Claim</option>
        <option value="Insurance">Insurance</option>  
        <option value="Warranty">Warranty</option>
        </select>
        </div>

和腳本

   $(document).ready(function(){
          $("#claim").change(function(){       
             $("#area").find(".field").remove(); 
             //or
               $('#area').remove('.field');
          if( $(this).val()=="Insurance")
             {
        $("#area").append("<input class='field' type='text' />");

             }
          });

});

示例http://jsfiddle.net/cqjJy/

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM