[英]Get content id (greatest) by clicking button on it Jquery
I need to get comment id when clicking to report button (I want to get comment-6) Now when I click 'report' it show a modal box with form. 我需要在点击报告按钮时获得评论ID(我想获得评论-6)现在,当我点击“报告”时,它会显示一个带有表单的模态框。
<div class="comment-box medium-comment" id="comment-6">
<div class="photo-box">
<img src="img/samples/photo_1.jpg" alt="" class="photo rounded"/>
<a href="#" title="" class="corner rounded"></a>
</div>
<div class="avatars">
<a href="#" title="">
<img src="img/samples/followers/1.jpg" alt=""/>dearskye
</a>
<span>commented on</span>
<a href="#" title="">
<img src="img/samples/followers/2.jpg" alt=""/>Antony12
</a>
</div>
<div class="comment rounded">
<div class="bg-tl"></div>
<div class="text">Happy golden days of yore
Happy golden days of yore Happy golden days
of yore</div>
<div class="buttons">
<a href="#" title="" class="report">REPORT</a>
</div>
</div>
<div class="cinfo">
2 дня назад
</div>
<div class="both"></div>
</div>
clicking to 点击
<a href="#" title="" class="report">REPORT</a>
call jquery 打电话给jquery
jQuery('a.report').bind('click', function(event) {
showModalWindow('report-window');
});
and function is 和功能是
function checkReportForm(form)
{
var result=true;
var select=jQuery("#report-window select");
var textarea=jQuery("#report-window textarea");
if(textarea.hasClass('default'))
{
//Save placeholder
textarea.data('placeholder', textarea.text());
textarea.toggleClass('default');
}
textarea.attr('class','rounded');
if(select.val()==0)
{
if(textarea.val()==''||textarea.val()==textarea.data('placeholder'))
{
result=false;
textarea.toggleClass("alert");
}
}
if(result)
{
closeModalWindow('report-window');
}
I tried to do it but nothing. 我试着这样做,但没有。 I suppose it is possible otherwise will think to change code. 我想有可能否则会考虑改变代码。 I hope someone will help me. 我希望有人会帮助我。
If i understand you correctly, the following should fetch the comment id for you: 如果我理解正确,以下内容应该为您获取评论ID:
$(".report").click(function() {
var $box = $(this).parents(".comment-box");
var commentId = $box.attr("id").replace("comment-", "");
// commentId contains 6
// call showModalBox and do whatever you want
});
You can use closest
to get the closest element which cotains the required class and get its id. 你可以使用closest
来获得最接近所需类的元素并获得它的id。 Try this. 尝试这个。
jQuery('a.report').click(function() {
var $commentBox = $(this).closest(".comment-box");
var id = $commentBox.attr('id').replace('comment-', '');
alert(id);//It will alert the comment id
//Store the comment id in report window
$('#report-window').data('commentid', id);
});
Now use $('#report-window').data('commentid')
to get the current comment id inside checkReportForm
method. 现在使用$('#report-window').data('commentid')
来获取checkReportForm
方法中的当前注释id。
当this
上下文是您的报告链接时:
var id = Number(this.parentNode.parentNode.id.substring(8));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.