[英]get id of calendar div on clicking next/prev button in calendar in jquery
[英]Get content id (greatest) by clicking button on it Jquery
我需要在點擊報告按鈕時獲得評論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>
點擊
<a href="#" title="" class="report">REPORT</a>
打電話給jquery
jQuery('a.report').bind('click', function(event) {
showModalWindow('report-window');
});
和功能是
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');
}
我試着這樣做,但沒有。 我想有可能否則會考慮改變代碼。 我希望有人會幫助我。
如果我理解正確,以下內容應該為您獲取評論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
});
你可以使用closest
來獲得最接近所需類的元素並獲得它的id。 嘗試這個。
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);
});
現在使用$('#report-window').data('commentid')
來獲取checkReportForm
方法中的當前注釋id。
當this
上下文是您的報告鏈接時:
var id = Number(this.parentNode.parentNode.id.substring(8));
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.