简体   繁体   English

jQuery UI对话框按钮不会单击

[英]jQuery UI Dialog Button Won't Click

The alert is working, but the button just won't click... 警报正在运行,但是按钮不会单击...

$('#loginDialog .field input').keyup(function (e) {
     if (e.keyCode == 13) {
         alert('it is working!');
         $('.ui-button').click();
         return false;
     }
});

I have tried many different things, including reinitializing the method when the dialog gets opened, but nothing seems to work... 我尝试了很多不同的方法,包括在打开对话框时重新初始化方法,但是似乎没有任何效果。

Html: HTML:

<div id="loginDialog" title="Please Login">
     <div class="label">Password:</div>
     <div class="field"><input type="password" /></div>
</div>

the ui-button is generated by jquery ui ui按钮由jquery ui生成

I'm assuming from your comment that the button is generated dynamically and that any click event you have bound to is will have to be bound using event delegation, similar to: 根据您的评论,我假设该按钮是动态生成的,并且绑定到您的任何click事件都必须使用事件委托来绑定,类似于:

$('body').on('click', '.ui-button', function(){...)

Instead of body , using the closest static element will work as well and would be preferred. 代替body ,使用最接近的静态元素也将起作用,因此将是首选方法。

Please, try this: 请尝试以下方法:

$(function() {
$('#loginDialog .field input').keyup(function (e) {
     if (e.keyCode == 13) {
         alert('it is working!');
         $('.ui-button').trigger('click');
         return false;
     }
});

$('.ui-button').click(function() {
   alert('hello world'); 
});
};

Here there is an example: http://jsfiddle.net/netme/YZH3B/ 这里有一个例子: http : //jsfiddle.net/netme/YZH3B/

这应该触发事件...

 $('.ui-button').trigger('click');

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

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