jquery获取下拉框的值

来源:互联网 发布:hr软件inuoji 编辑:程序博客网 时间:2024/05/18 03:56
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
  <style>


  div { color:red; }
  </style>
  <script src="jquery-1.8.0.js"></script>
  <script type="text/javascript">
    $(function(){
   $("select").change(function () {
          var str = "";
          $("select option:selected").each(function () {
                str += $(this).text() + " ";
              });
          //$("div").text(str);
 alert(str);
        })
        .change();


})
       
    


  </script>
</head>


<body>
   <select name="sweets" >
    <option>Chocolate</option>
    <option selected="selected">Candy</option>


    <option>Taffy</option>
    <option>Caramel</option>
    <option>Fudge</option>
    <option>Cookie</option>


  </select>
  <div></div>
</body>
</html>
0 0