gpt4 book ai didi

jquery - 如何将自定义 html 关闭按钮添加到 jQuery 对话框的主体?

转载 作者:行者123 更新时间:2023-11-27 22:31:00 24 4
gpt4 key购买 nike

类似问题:How to add my custom buttons with ids to a dialog-modal jquery object

我很好奇是否有人知道如何使用我添加到 .html 正文中的自定义按钮关闭我的 jQuery 对话框。我应该更改 onClick 值吗?什么?也许 Virtual Escape Key 是一种选择。我不想使用标题栏关闭或按钮 Pane 关闭来保留我正在进行的主题。谢谢!

这是我的:

<script>
$(function () {
var $dialog = $('<div></div>')
.html('')
.dialog({
autoOpen: false,
modal: true,
position: 'center',
draggable: false,
width:'40%';
$(".ui-dialog-titlebar").hide()
$("body").on('click', '#opener', function(e) {
var param = $(this).attr('data-AttrRatingID');
$dialog.html(param + "<br /><div id='modalClose' onclick='' class='formbtnshell' title='Close'><div class='formbtnwhtl'></div><div class='formbtnwhtr'></div><div class='formbtninside formbtninsidedelete'><div class='formbtntext'>Close</div></div></div>");
$dialog.dialog('open');
// prevent the default action, e.g., following a link
return false;
});
});

最佳答案

只需分配一个点击事件并关闭事件内的对话框。避免使用内联事件处理程序。

$(document).on('click', '#modalClose', function() {
$(dialogSelector).dialog('close');
});

更新

您在创建 fiddle 的方式上遇到了一些问题。永远不要嵌套事件。它会多次绑定(bind)事件,这不会让您获得预期的效果。

您正在将事件附加到 id=opener $("body").on('click', '#opener',

但是当你附加它时元素的id是不同的

// Declare the initial dialog outside the Click event
var $dialog = $('#dialogg');

$dialog.dialog({
autoOpen: false,
modal: true,
position: 'center',
draggable: false,
width: '40%',
buttons: {
"Close": function () {
$(this).dialog("close")
}
}
});

// Append the HTML and open the dialog
$('input').click(function () {
$dialog.html("<br /><a id='modalClose'>CloseMe</a>");
$dialog.dialog('open');
});

// Bind the click event that closes the modal
$("body").on('click', '#modalClose', function (e) {
// prevent the default action, e.g., following a link
e.preventDefault();

// Need to close the Modal
$dialog.dialog('close');
});

Check Fiddle $dialog.html("
CloseMe");

关于jquery - 如何将自定义 html 关闭按钮添加到 jQuery 对话框的主体?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17956419/

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