简体   繁体   English

如何关闭禁用下拉菜单打开?

[英]How to close disable dropdown opening?

  <div id=ControlId>
       <select id="' +ControlId + '_text" value="Select Options" style="max-width:150px;background:White;Width:150px"> <option selected>Select Options</option></select>
  </div>
  <div id=ControlId + "_child"  style="display: none" > 
      <table>
         <tr>
            <td valign="top" style="width: 165px" ><input type="checkbox" name="vehicle" value="Bike" /> option 1
            </td>
         </tr>
         <tr>
            <td valign="top" style="width: 165px" ><input type="checkbox" name="vehicle" value="Car" /> option 2
            </td>
         </tr>
         <tr>
            <td valign="top" style="width: 165px" ><input type="checkbox" name="vehicle" value="dog" /> option 3
            </td>
         </tr>
    </table>
   </div>

I have created dropdownlist for multiple selection as following, how to disable default dropdown opening 我已经为以下多项选择创建了下拉列表,如何禁用默认下拉列表

this is my actural event in JQuery : 这是我在JQuery中的实际事件:

$("#" + ControlId).click(function () {
       $("#" + ControlId + "_child").fadeIn("slow");
       $("#" + ControlId + "_child").toggle();
});

How to disable default dropdown opening? 如何禁用默认下拉菜单打开?

I'm not sure whether you're trying to disable the dropdown . 我不确定您是否要 禁用该下拉菜单 If so try using the below code to disable it. 如果是这样,请尝试使用以下代码将其禁用。

 
 
 
  
  $("#" + ControlId + "_text").attr("disabled", true);
 
  

Also check your HTML code, it has to be cleaned up. 还要检查您的 HTML代码,必须对其进行清理。

EDIT1: If you're using jQuery 1.6+, then try using prop; EDIT1:如果您使用的是jQuery 1.6+,请尝试使用prop;

 
 
 
  
  $("#" + ControlId + "_text").prop("disabled", true);
 
  

EDIT2: Hide to option when dropdown is clicked. 编辑2:单击下拉菜单时隐藏到选项。

 
 
 
  
  $("#" + ControlId).click(function () { $("#" + ControlId + " options").hide(); });
 
  

EDIT3: You're trying to have a placeholder for SELECT tag , currently it is unavailable. EDIT3:您正在尝试为SELECT标签添加一个占位符 ,当前不可用。 Remove your inline styles for select and add the following css to your code. 删除select的内联样式,然后将以下CSS添加到代码中。

 select { max-width:150px; background:White; height: 25px; } /* Hidden placeholder */ select option[disabled]:first-child { display: none; } 

check out this JSFiddle in Firefox. 在Firefox中查看此JSFiddle

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM