简体   繁体   English

如何在jQuery UI Selectmenu中触发“选择”事件

[英]How to trigger 'select' event in jQuery UI Selectmenu

I got this selectmenu: 我有这个选择菜单:

$( "#software" ).selectmenu({ 
    width : 'auto', 
    select: function( event, ui ) {
        //my code
    }
});

And I want to programmatically change the selected Item and trigger the 'select' state. 我想以编程方式更改所选项目并触发“选择”状态。

I do the following: 我执行以下操作:

$( "#software" ).val( 1 ).selectmenu( "refresh" ).trigger( "select" );

The selectmenu picks the right option and refreshes it but it doesn't trigger the 'select' state. 选择菜单选择正确的选项并刷新它,但不会触发“选择”状态。 How can I do this? 我怎样才能做到这一点?

You can do the following:- 您可以执行以下操作:

$( "#software" ).val(1).selectmenu("refresh").trigger("selectmenuselect");

You will need to bind an event listener to the selectmenuselect event like: 您将需要将事件侦听器绑定到selectmenuselect事件,例如:

$( "#software" ).on( "selectmenuselect", function( event, ui ) {
     alert('New Item Selected!')
});

Info: select( event, ui ) 信息: select( event, ui )

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

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