gpt4 book ai didi

Jquery $(this) 在类选择器中不起作用

转载 作者:行者123 更新时间:2023-12-01 08:19:03 24 4
gpt4 key购买 nike

感谢您的宝贵时间

我有以下 jquery ui 对话框

$(function() {
$( ".dialog" ).dialog({
title: $(this).attr('name')+'WHYYY',
autoOpen: false,
show: "blind",
hide: "explode"
});

html 很简单,如下所示:

    <div class="dialog" style="" id="helper" name="helper">
<textarea id="helper_e" name="helper_e">
some text
</textarea>
</div>
<!--and so on with multiple dialog classes with different id's and name's-->

打算以名字作为标题。

它不起作用,在标题中输出以下内容:

UNDEFINEDWHYYY
为什么?感谢您的提示

最佳答案

因为 this 并不像您所期望的那样引用 div.dialog。它指的是 window.document。你应该像这样重写它:

$(function() {
$('.dialog').each(function() {
var props = {
title: $(this).attr('name')+'WHYYY',
autoOpen: false,
show: "blind",
hide: "explode"
};

$(this).dialog(props);
});
});

关于Jquery $(this) 在类选择器中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8464423/

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