how to disable the multiple selection from the list box using jquery? or javascript?

隐身守侯 提交于 2019-12-04 07:54:06

You could do that with the following jQuery:

$(function(){
  $("select[name='listServiceTypes']").removeAttr('multiple');
});

However, it would be much better to do it at the server side. Rather than using Html.ListBox, it would be better to use Html.DropDownList:

<%=Html.DropDownList("listServiceTypes", 
                Model.ServiceTypeListAll, 
                new { style = "width: 500px;height:200px", size=4 }); %>

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.

This script will turn off multiple selection for all select controls on the page.

<script type="text/javascript">
    $(document).ready(function () {
        $('select').removeAttr('multiple');
    });
</script>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!