无法在查找结果上调用 jquery 对话框

发布于 2024-12-29 10:22:39 字数 876 浏览 4 评论 0原文

所有,

我试图在用户单击图像时显示 JQuery 对话框。

这是我的 HTML 的精简版本:

<div class="MyHelpButton" style="display: inline;">
    <img src="{{MEDIA_URL}}/img/MyHelpIcon.png"/>
    <div class="MyHelpText" title="MyTitle">
        here <i>is</i> <u>some</u> <b>text</b>
    </div>
</div>

和我的 JavaScript:

$(function() {
    $(".MyHelpText").dialog({autoOpen:false});
    $(".MyHelpButton").click(function() {
        $(this).find(".MyHelpText").dialog("open"); // this doesn't work
        //$(".MyHelpText").dialog("open"); // this works
    });
});

如您所见,dialog("open") 函数仅在我直接使用类选择器时才起作用,而不是在我使用 find() 函数时才起作用。但由于页面上可能加载 MyHelpButton,我必须能够找到这个特定的 MyHelpText(被单击的 MyHelpButton 的子级) - 因此我使用 find ()。

关于我做错了什么有什么想法吗?

感谢您的帮助。

All,

I am trying to make a JQuery dialog box appear when the user clicks an image.

Here's a stripped-down version of my HTML:

<div class="MyHelpButton" style="display: inline;">
    <img src="{{MEDIA_URL}}/img/MyHelpIcon.png"/>
    <div class="MyHelpText" title="MyTitle">
        here <i>is</i> <u>some</u> <b>text</b>
    </div>
</div>

And my JavaScript:

$(function() {
    $(".MyHelpText").dialog({autoOpen:false});
    $(".MyHelpButton").click(function() {
        $(this).find(".MyHelpText").dialog("open"); // this doesn't work
        //$(".MyHelpText").dialog("open"); // this works
    });
});

As you can see, the dialog("open") function only works when I use the class selector directly and not when I use the find() function. But since there will be potentially loads of MyHelpButtons on the page, I have to be able to find this particular MyHelpText (the one that is a child of the MyHelpButton that was clicked) - Hence my use of find().

Any ideas on what I'm doing wrong?

Thank you for your help.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

疏忽 2025-01-05 10:22:39

这有效:

$($(this).selector + " .MyHelpText").dialog("open"); 

带有 synatx $("{someselector} {anotherselector}") 的选择器会提示 jQuery 执行后代搜索如下所述:

http://api.jquery.com/descendant-selector/

This works:

$($(this).selector + " .MyHelpText").dialog("open"); 

A selector with the synatx $("{someselector} {anotherselector}") is prompts jQuery to perform a descendant search as documented here:

http://api.jquery.com/descendant-selector/

爱她像谁 2025-01-05 10:22:39

试试这个http://jsfiddle.net/heera/cL7nX/3,希望对你有帮助。

Try this http://jsfiddle.net/heera/cL7nX/3, hope it will help you.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文