网络编程
位置:首页>> 网络编程>> JavaScript>> javascript获取select标签选中的值

javascript获取select标签选中的值

作者:cg_program  发布时间:2024-05-09 10:34:41 

标签:javascript,select

var obj = document.getElementById("testSelect"); //定位id
var index = obj.selectedIndex; // 选中索引
var text = obj.options[index].text; // 选中文本
var value = obj.options[index].value; // 选中值

jQuery中获得选中select值

第一种方式

$('#testSelect option:selected').text();//选中的文本
$('#testSelect option:selected').val();//选中的值
$("#testSelect").get(0).selectedIndex;//索引

第二种方式

$("#tesetSelect").find("option:selected").text();//选中的文本
$("#tesetSelect").find("option:selected").val();
$("#tesetSelect").find("option:selected").get(0).selectedIndex;

0
投稿

猜你喜欢

手机版 网络编程 asp之家 www.aspxhome.com