Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
182 views
in Technique[技术] by (71.8m points)

javascript - cheerio data diffusion confusion

Have a list of such a links. Want the value of the data key using cheerio/JQuery selector. 1 link:

<a href="#" class="ui-btn.stuff.stuff2" data-diffusion-decimal="1.9090" >xxx</a>

Have tried this:

$("a.ui-btn.stuff.stuff2").each(function(i, r) {
            const decimal = $(r).data("diffusionDecimal");
}

Get decimal not defined.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

That should be:

$("a.ui-btn.stuff.stuff2").each(function(i, a) {
  const decimal = parseFloat($(a).attr("data-diffusion-decimal"))
}

I'm not sure about that class, you might need a[class="ui-btn.stuff.stuff2"]


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...