问题
I am having div of the comments like
<div>
<div>
Some message over here
</div>
<div style = "height:10px;"> <a id = "post_id_1" class = "showReply" href = "javascript: void(0)">Reply</a></div>
</div>
My Reply Box
<div id="replymsgbox" style="display: none;">
<form id="frmComment" novalidate="novalidate" method="POST" name="frmComment">
<div>
<textarea id="comment_text" class="" name="comment[text]"></textarea>
<div id="error_text"> </div>
</div>
<div>
<input type="submit" value="Post" name="Submit">
</div>
</form>
</div>
My Jquery :
//showCommentBox
$('a.showReply').live("click", function(e){
$('#replymsgbox', $(this).parent().next()).slideToggle('fast')
});
Will any one help me out. I am not able to open reply div or form. where I am doing wrong
回答1:
Use following with latest version of jQuery.
$('a.showReply').on("click", function(e){
$('#replymsgbox').slideToggle('fast')
});
回答2:
$(function() { // if javascript code is before html
$('a.showReply').click(function(e){
$('#replymsgbox').slideToggle('fast')
});
});
http://jsfiddle.net/gxLdd/
回答3:
$("a.showReply").on("click", function(){
$(this).parent().parent().next().slideToggle("slow");
});
Here is the test: http://jsfiddle.net/2HczB/
I used with next() because I saw on your code you tried to do with this way. It's better to call immediately the id of the div. However with my solution you can open exactly the reply after the message you clicked reply.
回答4:
EXAMPLE
$('a.showReply').on("click", function(e){
$('#replymsgbox').slideToggle('fast')
});
You'll also need some padding or space between the two div
s to make sure the content doesn't overlap. In the example I just added a <br/>
.
Please note the change from .live
to .on
, as it is now deprecated.
See Here:
As of jQuery 1.7, the .live() method is deprecated. Use .on() to attach event handlers.
Make sure the document is ready as well by putting your jQuery code within $(document).ready(function{ ... })
. I'm sure you're probably already doing this and just pasted the relevant code, but always good to make sure.
来源:https://stackoverflow.com/questions/12842585/how-to-open-reply-form-under-comments-div