English 中文(简体)
选定标签的展示价值
原标题:Getting displayed value of select tag
<select id="kamal">
<option value"ACTIVE">a<option>
<option value"DISABLED">b<option>
<option value"DELETED">c<option>
</select>

我想得到页上显示的价值,而不是选项标上显示的价值。

我有兴趣“了解”而不是“融合”。

i 书写时,document.getElementById(“kamal”); 数值:是指选择的价值出现在变量中。 但我想到所展示的价值。

请帮助我如何发挥这一作用。

www.un.org/spanish/ecosoc 注:通过采用下文所述的所有备选办法,它将给我选择方案的价值,我希望标明选定的选择。 我指的是在html页上显示的价值。

最佳回答

The solution you are looking for is:

获取价值:

var element = document.getElementById("kamal");
var selectedValue = element.options[element.selectedIndex].value;

获取案文:

var element = document.getElementById("kamal");
var selectedValue = element.options[element.selectedIndex].text;

EDIT:

工作实例:

rel=“noretinger”>http://jsfiddle.net/n85tW/6/

问题回答

Try :

var sel = document.getElementById("kamal")
alert(sel.options[sel.selectedIndex].value); 

http://jsfiddle.net/n85tW/"rel=“nofollow> 工作实例:

注:<option> tag应当与</option>

var element = document.getElementById("kamal"); var selectedValue = element.options[element.selectedIndex].innerHTML;

也是我的问题的解决办法。





相关问题
CSS working only in Firefox

I am trying to create a search text-field like on the Apple website. The HTML looks like this: <div class="frm-search"> <div> <input class="btn" type="image" src="http://www....

image changed but appears the same in browser

I m writing a php script to crop an image. The script overwrites the old image with the new one, but when I reload the page (which is supposed to pickup the new image) I still see the old one. ...

Firefox background image horizontal centering oddity

I am building some basic HTML code for a CMS. One of the page-related options in the CMS is "background image" and "stretch page width / height to background image width / height." so that with large ...

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签