我试图绑定一个按键(“输入”)来触发一个jQuery模态对象中的函数。在下面的代码中,我想在检测到按键事件时触发$(this).dialog(“login”)。但是,似乎我无法调用self.dialog(“登录”)。我看着这个错误的方式吗?jQuery UI模式问题
$("#login-dialog").dialog({
autoOpen: false,
height: 250,
width: 350,
modal: true,
open: function() {
var self = $(this);
$("#login-dialog").load("/accounts/login/", function() {
$("#id_username").focus()
.keypress(function(event) {
if (event.which == 13) {
event.preventDefault();
self.dialog("login");
}
});
});
},
buttons: {
close: function() {
$(this).dialog("close");
},
login: function() {
$.ajax({
type: "POST",
url: "/accounts/login/",
data: $("#login-form").serialize(),
success: function(data) {
var errors = $(data).find("#login-error").val();
if (errors) {
$("#error-message").replaceWith("<p class='error'>" + "Your username and password didn't match" + "</p>");
} else {
window.location = "/builder";
}
}
});
}
}
});
啊,多么愚蠢的我 - 我应该知道。感谢您的协助! – Beor