gpt4 book ai didi

javascript - jQuery ("#dialog").dialog ('close' ) 无法使用单独 View 上的按钮

转载 作者:行者123 更新时间:2023-11-28 07:25:52 25 4
gpt4 key购买 nike

我在 MVC 项目中有一个 ASP.NET View ,我试图在其中创建一个弹出对话框来创建数据。还有另一个被加载的 View ,该 View 有一个 id 为“btncancel_create”的按钮。我无法使用该按钮来关闭对话框。我正在使用 jQuery 2.1.3 和 jQuery UI 1.11.4。

这是按钮的代码:

<input type="button" value="Cancel" id="btncancel_create" />

这是 View :

$(document).ready(function () {
//alert("Document is ready");
var url = "";

$("#dialog-create").dialog({
title: 'Create User',
autoOpen: false,
resizable: false,
width: 400,
show: { effect: 'drop', direction: "up" },
modal: true,
draggable: true,
open: function (event, ui) {
$(".ui-dialog-titlebar-close").hide();
$(this).load(url);
}
});

$("#lnkCreate").on("click", function (e) {
url = $(this).attr('href');
$("#dialog-create").dialog('open');

return false;
});

//$("#btncancel_create").on("click", function (e) {
// $("#dialog-create").dialog("close");
// return false;
//});

$("#dialog-create").button("#btncancel_create").click(function (e) {
alert("btncancel_create was clicked");
$("#dialog-create").dialog('close');
return false;
});
});

<div id="dialog-create" style="display: none"></div>

<p>@Html.ActionLink("Create New", "Create", null, new { id = "lnkCreate" })</p>

如您所见,我尝试了其他不起作用的方法,该方法已被注释掉。未注释的按钮单击函数确实会返回警报,但不会关闭对话框。预先感谢您的帮助,如果您需要更多信息,请告诉我。

最佳答案

而不是
$("#btncancel_create").on("click", function (e) {...
(在我上面注释掉的代码中)
应该是
$(document).on("click", "#btncancel_create", function (e) {....

我在这里找到了答案:Turning live() into on() in jQuery .

关于javascript - jQuery ("#dialog").dialog ('close' ) 无法使用单独 View 上的按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29661443/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com