1、select元素在选择是找到选择的值和option中的值
1 <!DOCTYPE html> 2 <html> 3 <head lang="en"> 4 <meta charset="UTF-8"> 5 <title></title> 6 <script type="text/javascript" src="jquery-1.11.2.js"></script> 7 <script type="text/javascript"> 8 $(function(){ 9 $("select").change(function () { 10 $("span").eq(0).html($(this).val()) 11 $("span").eq(1).html($(this).find("option:selected").text()) 12 }) 13 $("span").eq(0).html($("select").val()) 14 $("span").eq(1).html($("select").find("option:selected").text()) 15 }) 16 17 </script> 18 </head> 19 <body> 20 测试:<select> 21 <option value = "1">hello</option> 22 <option value = "2">world</option> 23 <option value = "3">change</option> 24 <option value = "4">le</option> 25 </select> 26 <div>选中的值:<span ></span>;value值:<span></span></div> 27 </body> 28 </html>
时间: 2024-10-13 18:57:02