最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Reading selected value of dropdown list in HTML by jQuery - Stack Overflow

programmeradmin1浏览0评论

I am trying to read the value of the selectedID in a drop down list in html through jQuery but it keeps producing an error. Did I miss something?

<select style="width: 80px;" class="text ui-widget-content ui-corner-all" id="metaList">
<option value="4d5e3a8c418416ea16000000">Wikipedia</option>  
<option value="4d5e3a8c418416ea16010000">Twitter</option>  
<option value="4d5e3a8c418416ea16020000">DBPedia</option>  
<option value="4d64cd534184162629000000">test</option>          
</select>        

I tried which used to work before

var temp = $("#metaList").val(); 

but it produces NULL!

I am trying to read the value of the selectedID in a drop down list in html through jQuery but it keeps producing an error. Did I miss something?

<select style="width: 80px;" class="text ui-widget-content ui-corner-all" id="metaList">
<option value="4d5e3a8c418416ea16000000">Wikipedia</option>  
<option value="4d5e3a8c418416ea16010000">Twitter</option>  
<option value="4d5e3a8c418416ea16020000">DBPedia</option>  
<option value="4d64cd534184162629000000">test</option>          
</select>        

I tried which used to work before

var temp = $("#metaList").val(); 

but it produces NULL!

Share Improve this question edited Feb 23, 2011 at 12:14 Gordon 317k76 gold badges546 silver badges565 bronze badges asked Feb 23, 2011 at 11:58 Ahmad FaridAhmad Farid 14.8k45 gold badges98 silver badges138 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 2

Your function call is correct, but nothing is selected. That is the reason why NULL is returned.

Try:

var temp = $("#metaList option:selected").val(); 
发布评论

评论列表(0)

  1. 暂无评论