English 中文(简体)
CSS 显示: None; - > 与 jQuery 点击 () - > jQuery ComboBox
原标题:CSS Display:None; -> with jQuery Click() -> jQuery ComboBox

所以我注意到,当元素 lt;div 样式=" 显示: 无, "\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

Is it possible to get this to work? I have tested it here, and seems to work. http://jsfiddle.net/FBYhe/

我正在使用 jQuery UI - & gt; ComboBox 部件 。

这是我现在的密码

    <select name="labels" id="labelsList">
        <option>Filter By Label</option>
        <option selected>Show All</option>
        <option class="ClickMe">Filter By Label</option>
    </select>
    <script>
        $(document).ready(function(){
            $(".ClickMe").click(function() {
                alert( tets );
            });
        });
    </script>

所以我得到ZERO的警报 与此有关, 我不知道为什么, 但我相信它有 与显示:没有。

任何帮助都将不胜感激!

最佳回答

如果您正在使用 jQuery UI 组合框自动填充部件, 您正试图让此功能在单击时工作 :

<li class="ui-menu-item" role="menuitem">
  <a class="ui-corner-all" tabindex="-1">MENU ITEM</a>
</li>

与您职位上的 html 不同。

您需要绑紧

($"ui-menu项目");

如果您想要在单击 jQuery 界面部件时执行某东西

或黑黑此

$.widget( "ui.combobox", {
.
.
.
    .click(function() {
      // close if already visible
      if ( input.autocomplete( "widget" ).is( ":visible" ) ) {

        // here I guess you want your thing
        // 
        input.autocomplete( "close" );
        return;
      }

      // work around a bug (likely same cause as #5265)
      $( this ).blur();

      // pass empty string as value to search for, displaying all results
      input.autocomplete( "search", "" );
      input.focus();
    });
问题回答

您的代码不会对 IE 或 Chrome 起作用, 因为没有人在选项元素上执行 点击 事件 。 也许你可以添加一个更改 事件, 例如 :

<select name="labels" id="labelsList" onchange="test_click(this)">
     <option>Filter By Label</option>
     <option selected>Show All</option>
     <option class="ClickMe">Filter By Label</option>
</select>

<script>
function test_click(obj)
{
    if ($(obj[obj.selectedIndex]).hasClass("ClickMe"))
        alert("clicked!");
}
</script>

当您单击“ ClickMe” 类的任何元素时, 这将发出警告 。 您甚至可以将此项行为指定给您想要的任意选择, 包括 jQuery s 绑定变化( 在此情况下, 函数会稍有变化, 没有参数 obj, 并且使用“ this” 而不是 obj 函数体 ) 。

希望这有帮助

如果您想要在选中某个选项时执行某些脚本, 您必须获得该值, 并看到我所要求的内容 。

$( #labelsList).click(function() {
   if($(this).val ==  somevalue ){
      alert("I have selected the correct option");
   }
});




相关问题
WPF Datagrid, Setting the background of combox popup

I would like to change the color of the popup background when using a DatagridComboboxColumn in the WPF Toolkit datagrid. I ve edited the Template for a normal Combobox and it works great for selected ...

How to insert ComboBox item into ListBox? [winforms]

The question is very simple, How to insert ComboBox selected item into ListBox using c#? I have tried with this: listbox.Items.Add(combobox.SelectedItem); and some other permutations but it always ...

How do I bind a ComboBox to a one column list

I ve seen how to bind a ComboBox to a list that has columns like this: ItemsSource="{Binding Path=Entries}" DisplayMemberPath="Name" SelectedValuePath="Name" SelectedValue="{Binding Path=Entry}" But ...

Wpf Combobox Limit to List

We are using Wpf Combobox to allow the user to do the following things: 1) select items by typing in the first few characters 2) auto complete the entry by filtering the list 3) suggesting the first ...