无法访问 DOM 元素

Can't get to the DOM element

本文关键字:元素 DOM 访问      更新时间:2023-09-26

我的页面上有投票脚本(jQuery Raty),一切正常,但我想在投票后更改ajax中的费率数字。

在跨度类 .glosy 时遇到问题

我的网页:

<div class='"movie__rate'">
    <div class='"score'" data-score='"$czy_glosowal2[ocena]'" data-user='"$stat[id]'" data-movie='"$podobny_film[id]'"></div>
    <span class='"movie__rate-number'">
        <span class='"glosy'">170</span>
    głosów</span>
</div>

我的JS:

('.score').raty({
click: function(score) {
var licznik_komentarzy = $(this).find('.glosy').text();
var zapisanie_licznika = $(this).find('.glosy').val(licznik_komentarzy);
var dodanie_licznika = +$(this).find('.glosy').val() + 1;                   
$(this).find('.glosy').text(dodanie_licznika);
            }               
            });

尝试了不同的方法(next(),nextAll(),find()),但仍然无法弄清楚。

假设this实际上是元素(取决于插件的编写方式)......您在 DOM 树中寻找错误的方向。

closest()在树上寻找祖先。

您需要使用find()来查找.score的后代