我在 HTML 方面没有多少经验。我期待创建一个简单的列表框,但其中一个要求是不允许多重选择。列表框的大部分代码是这样的-
<select name="sometext" multiple="multiple"> <option>text1</option> <option>text2</option> <option>text3</option> <option>text4</option> <option>text5</option> </select>
但这允许多种选择。
在这里,一个类似的问题被提出,但是“最佳”的答案被否决了。所以我不知道还能怎么做。请帮帮我。
Remove the multiple="multiple" attribute and add SIZE=6 with the number of elements you want
you may want to check this site
http://www.htmlcodetutorial.com/forms/_SELECT.html
Just use the size attribute:
<select name="sometext" size="5"> <option>text1</option> <option>text2</option> <option>text3</option> <option>text4</option> <option>text5</option> </select>
To clarify, adding the size attribute did not remove the multiple selection.
The single selection works because you removed the multiple="multiple" attribute.
Adding the size="5" attribute is still a good idea, it means that at least 5 lines must be displayed. See the full reference here
For Asp.Net MVC
@Html.ListBox("parameterName", ViewBag.ParameterValueList as MultiSelectList, new { @class = "chosen-select form-control" })
or
@Html.ListBoxFor(model => model.parameterName, ViewBag.ParameterValueList as MultiSelectList, new{ data_placeholder = "Select Options ", @class = "chosen-select form-control" })