这是我的代码片段:http: //jsfiddle.net/natatkinson/xbWEb/
Javascript:
$(document).ready(function () {
$("#tags").select2({
maximumSelectionSize: 3
});
});
HTML:
<form name="form1" id="form1" action="" method="GET">
<fieldset>
<legend>Shoe Info</legend>
<dl> <dt>Name:</dt>
<dd>
<input type="text" name="name" id="name" size="40" placeholder="Shoe name" required autofocus>
</dd>
</dl> <dt>Tags:</dt>
<dd>
<select multiple="" name="tags" id="tags" style="width:100%;">
<option value="0">Select Tags</option>
<option value="2">racing flat</option>
<option value="3">track spikes</option>
<option value="1">trainer</option>
</select>
</dd>
</dl>
</fieldset>
<p class="submit-buttons">
<input type="submit" class="button1" name="submit" id="submit" value="Add Shoes" />
</p>
提交的只是 1 个值,而不是文档中说的逗号分隔列表。