你们如何利用贾瓦文从下游名单上获得选定价值? 我曾尝试过以下工作,但没有工作。
var sel = document.getElementById( select1 );
var sv = sel.options[sel.selectedIndex].value;
alert(sv);
你们如何利用贾瓦文从下游名单上获得选定价值? 我曾尝试过以下工作,但没有工作。
var sel = document.getElementById( select1 );
var sv = sel.options[sel.selectedIndex].value;
alert(sv);
它正在与我合作。
我有以下超文本:
<div>
<select id="select1">
<option value="1">test1</option>
<option value="2" selected="selected">test2</option>
<option value="3">test3</option>
</select>
<br/>
<button onClick="GetSelectedItem( select1 );">Get Selected Item</button>
</div>
And the following JavaScript:
function GetSelectedItem(el)
{
var e = document.getElementById(el);
var strSel = "The Value is: " + e.options[e.selectedIndex].value + " and text is: " + e.options[e.selectedIndex].text;
alert(strSel);
}
http://www.ohchr.org。 如果你与伙伴关系使用。 NET, The id change when made.
直接<代码> 劳动报酬
var sv = sel.value;
alert(sv);
您的代码可能失败的唯一原因是没有选定项目,然后是<代码>选择的Index 收益-1和代码中断。
希望能为你们工作
function GetSelectedItem()
{
var index = document.getElementById(select1).selectedIndex;
alert("value =" + document.getElementById(select1).value); // show selected value
alert("text =" + document.getElementById(select1).options[index].text); // show selected text
}
这里是一个简单的例子,可以了解 j鱼中下降的选定价值。
第一,我们设计了下降倡议
<div class="col-xs-12">
<select class="form-control" id="language">
<option>---SELECT---</option>
<option>JAVA</option>
<option>C</option>
<option>C++</option>
<option>PERL</option>
</select>
Next we need to write script to get the selected item
<script type="text/javascript">
$(document).ready(function () {
$( #language ).change(function () {
var doc = document.getElementById("language");
alert("You selected " + doc.options[doc.selectedIndex].value);
});
});
现在 改变降幅后,选定项目将保持警惕。
I would say change var sv = sel.options[sel.selectedIndex].value; to var sv = sel.options[sel.selectedIndex].text;
It worked for me. Directing you to where I found my solution Getting the selected value dropdown jstl
According to Html5 specs you should use -- element.options[e.selectedIndex].text
e. 例如,如果你选择了如下文框:
<select id="selectbox1">
<option value="1">First</option>
<option value="2" selected="selected">Second</option>
<option value="3">Third</option>
</select>
<br/>
<button onClick="GetItemValue( selectbox1 );">Get Item</button>
您可使用以下文字:
<script>
function GetItemValue(q) {
var e = document.getElementById(q);
var selValue = e.options[e.selectedIndex].text ;
alert("Selected Value: "+selValue);
}
</script>
接受和测试。
How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.
I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...
Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...
Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...
I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...
Is it possible for someone to give me a few pointers on how to display a multidimensional array in the form of a bar graph? The array is multidimensional, with three elements in each part - and the ...
Is it possible to reload a form after file-input change? I have a form where the user can chose an image for upload. I also have a php script which displays that image resized. I only wonder if it ...
I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.