简体   繁体   English

防止选择菜单小部件关闭

[英]Prevent selectmenu widget from closing

I have a selectmenu widget with a bunch of options. 我有一个带有许多选项的selectmenu小部件。 I'd like to add a "show more" button as the last option which would then either load in more options and refresh the widget or just toggle their visibility to show them if they had already been loaded in but were not visible (either method would be ok, I don't mind). 我想添加“显示更多”按钮作为最后一个选项,然后将其加载更多选项并刷新小部件,或者仅切换其可见性以显示它们是否已被加载但不可见(两种方法没关系,我不在乎)。

The problem is that click on the "show more" option then closes the select menu itself! 问题是单击“显示更多”选项,然后关闭选择菜单本身! There must be a work around for this, as allowing multiple options to be selected doesn't close the widget when you click on it. 必须对此进行解决,因为允许选择多个选项不会在您单击小部件时关闭它。

Any ideas? 有任何想法吗?

yes, disabled option could be helpfull 是的,禁用选项可能会有所帮助

But first give it an id, something like: 但是首先给它一个ID,像这样:

 <option id="other" disabled style="color: black; text-align: center;">Other choices</option>

then the js part ( with jQuery): 然后是js部分(使用jQuery):

function goToOther(){
    var url = "http://qwant.com";
    window.location = url;
}


$( document ).ready(function() {
    $('#other').on('click', function(){
       goToOther();
    });
});

Set data-native-menu to true and enhance the menu jqm style with css, something like: 将data-native-menu设置为true并使用css增强菜单jqm样式,例如:

 .fakeList{background-clip: padding-box; background-color: rgb(246, 246, 246); border-bottom-color: rgb(221, 221, 221); border-bottom-left-radius: 5px; border-bottom-right-radius: 5px; border-bottom-style: solid; border-bottom-width: 1px; border-left-color: rgb(221, 221, 221); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(221, 221, 221); border-right-style: solid; border-right-width: 1px; border-top-color: rgb(221, 221, 221); border-top-left-radius: 5px; border-top-right-radius: 5px; border-top-style: solid; border-top-width: 1px; box-shadow: rgba(0, 0, 0, 0.15) 0px 1px 3px 0px; color: rgb(51, 51, 51); cursor: pointer; display: block; font-family: sans-serif; font-size: 16px; font-weight: 700; line-height: 20.8px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; opacity: 1; overflow: hidden; overflow-x: hidden; overflow-y: hidden; padding-bottom: 11.2px; padding-left: 16px; padding-right: 40px; padding-top: 11.2px; position: relative; text-align: center; text-decoration: none; text-decoration-color: rgb(51, 51, 51); text-decoration-line: none; text-decoration-style: solid; text-overflow: ellipsis; text-shadow: rgb(243, 243, 243) 0px 1px 0px; white-space: nowrap; -moz-user-select: none; } 

then in the js : 然后在js中:

 $( document ).ready(function() { $('option').addClass('fakeList'); $('#showMore').on('click', function(){ alert("do show more"); }); }); 

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

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