jQuery 的 find() 是“order”;具体的?为什么如果顺序改变 find 会返回零?
无论如何,我不是 jQuery 专业人士,我花了很长时间才弄清楚如何让“它”正常工作,
这是一段代码: 这是
$(this).parents('li:eq(0)').find('.dataPostArea').replaceWith(text); //1
$(this).parents('li:eq(0)').find('.hoverMenu').show(); //2
html:
<li class="post issuePost" data-winbook-contentType="Issue" data-winbook-issueId="null">
<div style="display:none;" class="hoverMenu">
<a href="#delete">
<img class="hoverButton deleteButton" src="deleteredicon.png"/>
</a>
<a href="#edit">
<img class="hoverButton editButton" src="editpencil.png"/>
</a>
</div>
<div class="postContainer">
<div class="avatarColumn">
<a href="#">
<img src="defaultavatar.jpg"/>
</a>
<div class="authorName">
<a href="#">Nupul</a>
</div>
</div>
<div class="postDetailsContainer">
<div class="dataPostArea">
<textarea class="dataForm" style="float:left; min-height:50px; min-width:330px; resize:none; margin:2px; margin-bottom:5px; overflow-x:hidden;" name="data">
</textarea>
<button class="addDataButton" style="width:95px; margin:3px 2px; padding:1px 4px 1px 4px;">
Add Issue
</button>
<button class="cancelDataButton" style="width:95px; margin:3px 2px; padding:1px 4px 1px 4px;">
Cancel
</button>
<div class="clear"/>
<span>10 characters left</span>
</div>
</div>
</div>
<div class="clear">
</div>
</li>
现在,如果 1 和 2 的顺序是如图所示,“.hoverMenu”从未显示。事实上,该 jQuery 对象的大小为零!如果 2 在 1 之前,则效果很好。我不知道为什么。有什么想法吗?
(如果您想知道我想要完成什么:只需将可编辑文本区域中的内容替换为该列表项的内容即可。类似于 stackoverflow 的“添加评论”功能:)
我可能是非常欢迎执行不正确的“查询”和更正。我没有缓存 $(this).parents('li:eq(0)')
并且认为这对这个问题来说并不重要。 (应该吗?)
I'm not a jQuery pro by any means and it took me quite a while to figure out how to get 'it' to work right
Here are is the piece of code:
$(this).parents('li:eq(0)').find('.dataPostArea').replaceWith(text); //1
$(this).parents('li:eq(0)').find('.hoverMenu').show(); //2
Here's the html:
<li class="post issuePost" data-winbook-contentType="Issue" data-winbook-issueId="null">
<div style="display:none;" class="hoverMenu">
<a href="#delete">
<img class="hoverButton deleteButton" src="deleteredicon.png"/>
</a>
<a href="#edit">
<img class="hoverButton editButton" src="editpencil.png"/>
</a>
</div>
<div class="postContainer">
<div class="avatarColumn">
<a href="#">
<img src="defaultavatar.jpg"/>
</a>
<div class="authorName">
<a href="#">Nupul</a>
</div>
</div>
<div class="postDetailsContainer">
<div class="dataPostArea">
<textarea class="dataForm" style="float:left; min-height:50px; min-width:330px; resize:none; margin:2px; margin-bottom:5px; overflow-x:hidden;" name="data">
</textarea>
<button class="addDataButton" style="width:95px; margin:3px 2px; padding:1px 4px 1px 4px;">
Add Issue
</button>
<button class="cancelDataButton" style="width:95px; margin:3px 2px; padding:1px 4px 1px 4px;">
Cancel
</button>
<div class="clear"/>
<span>10 characters left</span>
</div>
</div>
</div>
<div class="clear">
</div>
</li>
Now if the order of 1 and 2 is as shown '.hoverMenu' is never shown. In fact the size of that jQuery object is zero! If 2 is before 1 it works fine. I'm not sure why. Any ideas?
(In case you want to know what I'm trying to accomplish: Just taking the content in an editable textarea and replacing the textarea with that content for that list item. Similar to the "add comment" functionality of stackoverflow :)
I may be performing an incorrect 'query' and corrections are more than welcome. I've not cached the $(this).parents('li:eq(0)')
and don't think it should matter for this problem. (Should it?)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的
$(this)
对象是一个发生的情况是,这一行将
删除按钮对象
$(this)
,使第二行 void 。这就是为什么它向您显示它不存在(没有找到任何),这就是为什么当您切换时它可以工作,如果您想保持订单做这样的事情
your
$(this)
object is a<button class="addDataButton">
, correct? which you replace with txt once you post. corrrect?what happened is that this line
will remove the button object
$(this)
, making then second line void . Thats why it showed you that it dosen't exist (didn't find any) and thats why when you switch over it worksif you want to keep the order do something this