【发布时间】:2013-06-24 09:49:46
【问题描述】:
刚刚写了一个jquery来显示一个评论按钮,当点击textarea时。隐藏评论按钮点击屏幕上的其他地方。 它在 Firefox 中运行良好。但是在 Chrome 中它只工作一次。当我再次点击 textarea 时,提交按钮没有显示,它仍然隐藏。
$(document).on('click', ".comment_txt, .comment_btn", function() {
var post_id = $(this).attr("post-id");
$("#comment_btn_div_"+post_id).show();
});
$('body').click(function() {
$(".comment_btn").hide()
});
<form class="comment_submit" action="http://localhost:3000/api/v2/posts/48774/comment" data-post-id="48774" id="comment_form_48774">
<textarea post-id="48774" id="comment_txt_48774" placeholder="Comment" cols="40" rows="1" class="width100 comment_txt"></textarea>
<div id="comment_btn_div_48774" class="right comment_btn" post-id="48774" style="display:none">
<button onclick="$(this).text('commenting...')" class="btn btn-small btn-info right" id="comment_btn_48774" type="submit">Comment</button>
</div>
</form>
不知道为什么这在 Chrome 中不起作用。我的页面中有很多表格。所以我在身体点击时做了$(".comment_btn").hide()。为了显示特定的评论按钮,我使用此代码$("#comment_btn_div_"+post_id).show();
更新:
隐藏评论按钮后,即使我从萤火虫控制台执行 $("#comment_btn_div_23232").show() 。它没有显示div。
更新 2(使用警报测试):
$(document).on('click', ".comment_txt, .comment_btn", function() {
alert("commenttext area clicked");
$(".comment_btn").show()
});
$('body').click(function() {
alert("body clicked");
$(".comment_btn").hide()
});
- 单击文本区域,收到警报 a。身体点击 b.评论文本区域单击。现在显示评论按钮
- 单击的正文收到警报 a。身体咔哒一声。现在评论按钮被隐藏了
- 单击文本区域,收到警报 a。身体点击 b.评论文本区域单击。现在评论按钮不显示。
谢谢!
【问题讨论】:
-
div "comment_btn_div_48774" 是你身体的一部分。
-
是的,是身体的一部分
-
对我来说很好。你有任何错误吗?
-
不,我没有收到任何错误。请注意,我的页面中有很多表格。所以我做了 $(".comment_btn").hide()。为了使用此代码显示特定的评论按钮 $("#comment_btn_div_"+post_id).show();
-
为什么你将你的点击事件与“.comment_btn”绑定,也作为它的一部分。
标签: javascript jquery google-chrome show-hide