<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title></title> <script type="text/javascript" src="jquery-3.2.1.min.js"></script> </head> <body> <form name="a"> <select name="selecta" size="1" id="selectb" > <option value="a">1</option> <option value="b">2</option> <option value="c">3</option> </select> <button onclick="foo()">选择</button> </form> <script type="text/javascript"> function foo(){ var i = document.getElementById("selectb").selectedIndex; var v1 = document.getElementsByTagName("option")[i].value;// a var v2 = document.getElementsByTagName("option")[i].text;// 1 var v3 = $("#selectb option:selected").val();// b var v4 = $("#selectb option:selected").text();// 2 var v5 = $("#selectb").val();// c var v6 = $("#selectb").text();// 1 2 3 var v7 = $("#selectb").text();// 1 2 3 var v8 = $("#selectb").find("option:selected").val(); // a var v9 = $("#selectb").find("option:selected").text(); // 1 alert(v1); } </script> </body> </html>
原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/20738.html