Jquery 多选下拉框取值

来源:互联网 发布:软件前景 编辑:程序博客网 时间:2024/06/06 02:30
<!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(){$("input:button").click(function() {var all = "";$("select option").each(function() {all += $(this).attr("value")+" ";});var sel = $("select").val();alert("多选列表所有的value值:"+all+" 其中被选中的是:"+sel );});})</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>   <input type="button" value="点击显示选择的项目"></form></body></html>

0 0
原创粉丝点击