答案 0 :(得分:0)
我使用Select2执行此操作:
<强>代码:强>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width" />
<title>Hello</title>
<script src="https://code.jquery.com/jquery-2.2.4.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.3/css/select2.min.css" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.3/js/select2.full.min.js"></script>
<script>
$(function () {
$(".select2").select2({
maximumSelectionLength: 3,
width: 350
});
});
</script>
</head>
<body>
<select name="tags" id="tags" class="select2" multiple="multiple">
<option value="PHP">PHP</option>
<option value="CSS">CSS</option>
<option value="CPP">C++</option>
<option value="JavaScript">JavaScript</option>
</select>
</body>
</html>
<强>段强>
$(function () {
$(".select2").select2({
maximumSelectionLength: 3,
width: 350
});
});
<script src="https://code.jquery.com/jquery-2.2.4.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.3/css/select2.min.css" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.3/js/select2.full.min.js"></script>
<select name="tags" id="tags" class="select2" multiple="multiple">
<option value="PHP">PHP</option>
<option value="CSS">CSS</option>
<option value="CPP">C++</option>
<option value="JavaScript">JavaScript</option>
</select>
演示: JSBin