select获取选中项的值与文本

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<select id="test" name="">
<option value="1">text1</option>
<option value="2">text2</option>
</select>
<button id="my">获取</button>
</body>
<script src="jquery-2.2.2.min.js"></script>
<script>
$("#my").on("click",function () {
var textValue = $("#test option:selected");
console.log(textValue.val());//值
console.log(textValue.text());//文本
})
</script>
</html>

上一篇:idea controller service impl mapper xml切换跳转快捷键


下一篇:Linux部署jar