gpt4 book ai didi

javascript - 获取 jQuery 对话框中的底层元素

转载 作者:行者123 更新时间:2023-12-02 16:15:08 25 4
gpt4 key购买 nike

我想将一个 jQuery 对话框附加到它当前的父级(比方说,因为它包含输入,并且它的父级是表单中的子级)。所以问题如下:

http://jsfiddle.net/pprrm4st/2/

我确实需要找到当前元素的 .container 并将对话框附加到它。

appendTo: $(this).closest('.container'), //I thougnt $(this) would be current .element

否则有没有办法告诉 jQuery 不要将 .element 移动到任何地方?

最佳答案

this 不是该范围内的元素,您应该注意,没有函数调用会设置 this 值。

以下是如何使用 each 循环解决该问题,其中 this 是元素等。

$(".element").each(function() {
$(this).dialog({
modal: true,
autoOpen: false,
appendTo: $(this).closest('.container'),
buttons: {
"I've read and understand this": function() {
$(this).dialog("close");
}
}
});
});

$('a').click(function(){
$(".element").dialog('open');
});

FIDDLE

关于javascript - 获取 jQuery 对话框中的底层元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29701723/

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