无法在查找结果上调用 jquery 对话框
所有,
我试图在用户单击图像时显示 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这有效:
带有 synatx $("{someselector} {anotherselector}") 的选择器会提示 jQuery 执行后代搜索如下所述:
http://api.jquery.com/descendant-selector/
This works:
A selector with the synatx $("{someselector} {anotherselector}") is prompts jQuery to perform a descendant search as documented here:
http://api.jquery.com/descendant-selector/
试试这个http://jsfiddle.net/heera/cL7nX/3,希望对你有帮助。
Try this http://jsfiddle.net/heera/cL7nX/3, hope it will help you.