Jquery下拉框取值

<!DOCTYPE html>
<html>
<head>
   <title>Bootstrap 實例 - 選擇框</title>
   <link href="http://libs.baidu.com/bootstrap/3.0.3/css/bootstrap.min.css" rel="stylesheet">
   <script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
   <script src="http://libs.baidu.com/bootstrap/3.0.3/js/bootstrap.min.js"></script>
   <script>
	   $(function() {
        $("select").change(function(event) {
			////獲取當前選擇的下一項的值
            //var obj = $(this).find("option:selected").next();
            //alert("選中項的下一個: 內容"+obj.html()+",值"+obj.val());

			//獲取當前選擇的下一項的值
            var obj = $(this).find("option:selected");
            alert("選中項的: 內容"+obj.html()+",值"+obj.val());
        });
         
    }) 
	</script>
	
	<style>
		select{width:200px;height:500px;padding:10px;border:4px dashed #ccc;}
		select option{margin:5px;}
		input[type='button']{width:200px;height:35px;margin:10px;border:2px dashed #ebbcbe;}
	</style>
</head>
<body>

<form role="form">
   
   <select id="multi-sel" multiple="multiple">
	<option value="1">蘿蔔,我的value是1</option>
	<option value="2">青菜,我的value是2</option>
	<option value="3">小蔥,我的value是3</option>
	<option value="4">豆腐,我的value是4</option>
   </select>
	
</form>

</body>
</html>

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章