2014-11-24 110 views
0

我正在使用Jquery Mobile显示选择框的下拉菜单。如何在jQuery Mobile中的选择框中禁用打开下拉菜单

<select id="category_type" multiple="multiple" class="category" tabindex="-1" placeholder="Category"> 
<option></option> 
. 
. 
</select> 

在某些情况下,我需要限制单击时打开选择框的下拉菜单。

我试着用

jQuery("#category_type").bind("change", function(e) { 
    jQuery.mobile.selectmenu.prototype.options.hidePlaceholderMenuItems = false; 
    e.preventDefault(); 
}); 

但没有效果。 怎么可能? 在此先感谢

+0

你是什么意思,限制开放? – Omar 2014-11-24 06:50:13

+0

@Omar感谢您的回复。我其实是指在点击选择菜单时禁用或阻止选项列表。我不需要显示在选择框中单击时填充的选项列表,但风格和所有需要我。 – 2014-11-24 06:54:05

+0

禁用它http://stackoverflow.com/a/19682317/1771795 – Omar 2014-11-24 07:31:05

回答

0

注意:这里是工作DEMO

HTML部分:

<div data-role="fieldcontain"> 
    <button id="disable_select">Disable</button> 
    <select name="select-choice-1" id="select-choice-1"> 
     <option value="standard">Standard: 7 day</option> 
     <option value="rush">Rush: 3 days</option> 
     <option value="express">Express: next day</option> 
     <option value="overnight">Overnight</option> 
    </select> 
</div> 

JS部分:

$("#disable_select").click(function() { 
    $("#select-choice-1").attr("disabled","disabled"); 
}); 

现在我已经添加了一个按钮禁用点击该按钮的下拉列表,你可以添加你的条件来禁用它。

+0

感谢您的回复。这个属性我已经使用,但没有效果 – 2014-11-24 10:30:07

+0

@VishnuPrasad但完全在我身边工作。问题是什么 ?? – 2014-11-24 14:59:33

+0

我发起了一种方法来禁用HTML本身中的选择框......并在需要时启用它..其目前的活动,我made.But如果我得到开放事件的jQuery的移动,那么问题可以修复 – 2014-11-25 04:14:49

相关问题