select 多選
阿新 • • 發佈:2020-12-09
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>MULTIPLE SELECT</title> <script src="https://cdn.bootcss.com/jquery/2.1.4/jquery.min.js"></script> <link href="https://cdn.bootcss.com/multiple-select/1.2.0/multiple-select.min.css" rel="stylesheet"> <script src="https://cdn.bootcss.com/multiple-select/1.2.0/multiple-select.min.js"></script> </head> <body> <select id="fruit" multiple style="width:130px;"> <option value="1">蘋果</option> <option value="2">桔子</option> <option value="3">香蕉</option> <option value="4">葡萄</option> <option value="5">山竹</option> <option value="6">榴蓮</option> </select> <input name="fruit" placeholder="值"> <input type="button" onclick="testV()" value="測試" /> <script> $(function(){ $('#fruit') .multipleSelect({ selectAll:false ,placeholder:'你喜歡的水果?' }) .change(function(){ $('[name=fruit]').val($(this).val()?$(this).val().join(','):'') }) }) function testV(){ var fruit = $('#fruit').val(); alert(fruit); } </script> </body> </html>