如何使用click事件在jquery raty插件中获取一些参数值?(How can I get some parameter value in jquery raty plugin, with cl

编程入门 行业动态 更新时间:2024-10-25 19:32:45
如何使用click事件在jquery raty插件中获取一些参数值?(How can I get some parameter value in jquery raty plugin, with click event?)

我正在做一个项目。 它看起来像一个博客网站。 在索引页面中,我添加了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"

更多推荐

本文发布于:2023-08-03 09:42:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1385243.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何使用   插件   参数   事件   raty

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!