我正在做一个项目。 它看起来像一个博客网站。 在索引页面中,我添加了raty插件来评价该文章。 当我评价帖子时,我会通过点击事件获得价值。 我需要raty函数的click函数的文章id和用户id。 我怎么能得到这个?
我的HTML代码:
<div class="col-lg-7 col-md-7 col-sm-7 col-xs-7"> <h2 class="book-title"><%= user[i].writeArticle[j].title%></h2> <h4 class="book-writer">লেখাঃ <%= user[i].name%></h4> <h4 class="book-writer">ছবিঃ সংগৃহীত</h4> <h4 class="sub-level"><%= user[i].writeArticle[j].cetagory%></h4> <h4 class="sub-level"> লেভেল :<span><%= user[i].writeArticle[j].label%></h4> <span class="star"> </span> </div>我的Jquery代码:
$('.star').raty({ click: function(score, evt) { var rating=score; console.log(rating); // need article title here: } });I am working on a project. Its looking like a blog site. In index page, i have added raty plugin for rate the article. When I rate a post, i am getting ratting value by click event. I need that article id & user id on click function of raty function. How can I get this ?
My HTML code :
<div class="col-lg-7 col-md-7 col-sm-7 col-xs-7"> <h2 class="book-title"><%= user[i].writeArticle[j].title%></h2> <h4 class="book-writer">লেখাঃ <%= user[i].name%></h4> <h4 class="book-writer">ছবিঃ সংগৃহীত</h4> <h4 class="sub-level"><%= user[i].writeArticle[j].cetagory%></h4> <h4 class="sub-level"> লেভেল :<span><%= user[i].writeArticle[j].label%></h4> <span class="star"> </span> </div>My Jquery code:
$('.star').raty({ click: function(score, evt) { var rating=score; console.log(rating); // need article title here: } });最满意答案
您可以在.star元素上添加id作为data-title-id和data-user-id属性。 然后在事件处理程序中,您可以执行$(this).attr('data-title-id')来获取标题ID。
编辑示例:
<span class="star" data-title-id="74">现在在点击处理程序中
$(this).attr('data-title-id')应该返回“74”
You can add the id's as data-title-id and data-user-id attributes on the .star element. Then in the event handler you can do $(this).attr('data-title-id') to get the title id.
Edit example:
<span class="star" data-title-id="74">Now in the click handler
$(this).attr('data-title-id')Should return "74"
更多推荐
发布评论