
html:
<select
id="sel">
<option
value='s1'>苹果</option>
<option
value='s2'>西瓜</option>
<option
value='s3'>香蕉</option>
</select>
javascript:
$(function(){
var
_val
=
$map(
$("#sel
option:not(:selected)"),
function(ele){return
elevalue}
)join(",");
alert(_val);
})
其中主要的是:$("#sel
option:not(:selected)"),这是返回没被选中的option集合,
使用$map函数对这个集合进行处理,取出其中元素的值,使用","进行分隔。
如果option中没有value属性,那么直接返回option的文本内容。
var obj = documentgetElementById("n1"); // 这里也可以写成var obj = documentgetElementByName("n1");var arrText = new Array();var arrValue = new Array();
for(var i = 0; i < objoptionslength; i++) {
arrText [arrText length] = objoptions[i]text; arrValue[arrValuelength] = objoptions[i]value;
}arrText 就是所有的TextarrValue就是所有的Value
通过option:selected方法来获取文本值
<!--HTML部分-->
<select class="select">
<option>桃子</option>
<option>苹果</option>
<option>桔子</option>
</select>
<p class="text">我是<span></span></p>
<!--JS部分-->
<script type="text/javascript">
$(function(){
var b;
$("select")on("click",function(){
b=$(this)children("option:selected")text(); //通过option:selected方法来获取文本值
$("text span")text(b);
})
});
</script>
如果我选择的是苹果,那会就会输出"我是苹果"
单选下拉列表框对象的value属性值就是选中项的value值,因此只需用如下代码即可
1
var selected_val = documentgetElementById(select_id)value;
并且,通过 *** 作select下的option也可以得到被选项的value值,方法为:
var sel = documentgetElementById(select_id);
var selected_val = seloptions[selselectedIndex]value;
实例演示如下:
1、HTML结构及javascript代码
<select id="test" onchange="alert(thisvalue)">
<option value="0">options-0</option>
<option value="1">options-1</option>
<option value="2">options-2</option>
</select>
在你的代码后添加下面代码,就可以在修改select选择后,得到每个select中的值了。
<div id="output_div"></div>
<script type="text/javascript">
$(function(){
output_func();
$("select")change(output_func);
});
function output_func(){
var str="输出显示为:<br>";
$("tr")each(function(){
$(this)find("td")each(function(){
str+="<span style='border:1px solid blue;'>"+$(this)find("select")val()+"</span> ";
});
str+="<br>";
});
$("#output_div")html("<br>" + str);
}
</script>
以上就是关于js或者jquery如何获取select中未选中的值急求全部的内容,包括:js或者jquery如何获取select中未选中的值急求、通过js来获取select的全部值、如何用js获取select选项文本的代码呢等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)