侧边栏壁纸
博主头像
千古互动

QQ:54505339

  • 累计撰写 40 篇文章
  • 累计收到 1 条评论

js获取当前被选中的option值

2024-5-5 / 0 评论 / 501 阅读

<!doctype html>

<html>

<head>

<meta charset="utf-8">

<title>无标题文档</title>

</head>

<body>

<select id="sel" onchange="cge()">

<option value="1">4</option>

<option value="2">5</option>

<option value="3">6</option>

</select>

</body>

<script>

function cge(){

var sel=document.getElementById('sel');

var sid=sel.selectedIndex;

alert(sel[sid].value+'-'+sel[sid].innerHTML);

}

</script>

</html>

jq的话就一句

$("#sel option:selected").text();

$("#sel option:selected").val();