2014-02-26 53 views
0

我希望用戶在提示框中輸入一段文字。使用提醒框詢問用戶輸入

HTML:

<form> 
    <select class="favoritefood"> 
     <optgroup label="Dairy products"> 
      <option>Cheese</option> 
      <option>Egg</option> 
      <option id="newDairy">NEW</option> 
     </optgroup> 
     <optgroup label="Vegetables"> 
      <option>Cabbage</option> 
      <option>Lettuce</option> 
      <option>Beans</option> 
      <option>Onions</option> 
      <option>Courgettes</option> 
      <option id="newVeg">NEW</option> 
     </optgroup> 
    </select> 
</form> 

JS:

$('.favoritefood').change(function() { 
    var id = $(this).find('option:selected').attr('id'); 
    if (id == 'newDairy') { 
     alert("input"); 
    }; 
}); 

我知道這是可能有警告框裏面輸入,但如何?

回答

5

這將是提示框

var result = prompt('type something'); 

FIDDLE