如何禁用从使用jQuery列表框中多项选择?或JavaScript? [英] how to disable the multiple selection from the list box using jquery? or javascript?
问题描述
我有一个列表框在我的网页。
I have a list box in my page..
<td><%=Html.ListBox("listServiceTypes", Model.ServiceTypeListAll, new { style = "width: 500px;height:200px;" })%>
我需要从列表框中选择禁用多个项目?我在做类似选择一个项目,然后单击删除按钮我的网页其delting从列表框中选择一个项目。但如果我选择multple项目其抛出的错误消息/.?
I need to disabled selecting multiple items from the list box? I am doing something like selecting one item and click delete button my page its delting one item from list box.. but If I select multple Items its throwing an error message/.?
任何机构可以帮助我如何取消激活或禁用从列表框中选择多个项目
Can any body help me out how to deactive or disable multiple items from list box
推荐答案
您的可能的做用下面的jQuery的:
You could do that with the following jQuery:
$(function(){
$("select[name='listServiceTypes']").removeAttr('multiple');
});
不过,这将是更好的在服务器端做。而不是使用 Html.ListBox
,这将是更好地使用 Html.DropDownList
:
<%=Html.DropDownList("listServiceTypes",
Model.ServiceTypeListAll,
new { style = "width: 500px;height:200px", size=4 }); %>
此不必做任何的jQuery / JavaScript作为它产生pretty大致相同的HTML删除多个
属性,但没有<$ C不再需要$ C>多个属性。具有尺寸
大于1告诉来显示它作为一个多行列表框中浏览器的值。
This removes the need from having to do any jQuery/JavaScript to remove the multiple
attribute as it produces pretty much the same HTML but without the multiple
attribute. Having a value for size
that is greater than 1 tells the browser to display it as a multi-line list box.
这篇关于如何禁用从使用jQuery列表框中多项选择?或JavaScript?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!