如何查找和更改没有ID的span和div中的文本?
<div style="text-align:center;float:left;width:100%;fontsize:12px;padding:12px 0 16px 0;line-height:1.25em;">
**VOLUME (24H)**
<br><br>
<span style="font-size: 14px; ">**$2.99 M**</span>
</div>
我想找到VOLUME (24H)
和$2.99 M
这不是常数,并替换为我的文字。我怎么能这样做?
我不能放ID,因为我从这段代码中得到了这个:
<script type="text/javascript" src="https://files.coinmarketcap.com/static/widget/currency.js"></script>
<div class="coinmarketcap-currency-widget" data-currency="nexus" data-base="PLN" data-secondary="" data-ticker="true" data-rank="false" data-marketcap="false" data-volume="true" data-stats="USD" data-statsticker="false">
</div>
答案 0 :(得分:1)
完全位置,非常脆弱。
var $div = $('.coinmarketcap-currency-widget').find('> div > div:nth-child(2) > div');
var $contents = $div.contents();
console.log($contents.eq(0).text().trim());
console.log($contents.eq(5).text().trim());
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="coinmarketcap-currency-widget" data-currency="nexus" data-base="PLN" data-secondary="" data-ticker="true" data-rank="false" data-marketcap="false" data-volume="true" data-stats="USD" data-statsticker="false">
<div style="border:2px solid #E4E6EB;border-radius: 10px;font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif;min-width:285px;">
<div>
<div style="float:right;width:67%;border: 0px solid #000;text-align:left;padding:5px 0px;line-height:30px;">
<span style="font-size: 18px;"><a href="http://coinmarketcap.com/currencies/nexus/?utm_medium=widget&utm_campaign=cmcwidget&utm_source=&utm_content=nexus" target="_blank" style="text-decoration: none; color: rgb(66, 139, 202);">Nexus (NXS)</a></span>
<br>
<span style="font-size: 16px;">13.55 PLN <span style="color:#d14836">(-5.34%)</span>
</span>
</div>
<div style="text-align:center;padding:5px 0px;width:33%;"><img src="https://files.coinmarketcap.com/static/img/coins/64x64/nexus.png"></div>
</div>
<div style="border-top: 1px solid #E4E6EB;clear:both;">
<div style="text-align:center;float:left;width:100%;font-size:12px;padding:12px 0 16px 0;line-height:1.25em;">
VOLUME (24H)
<br>
<br>
<span style="font-size: 14px; ">$3 M</span>
</div>
</div>
<div style="border-top: 1px solid #E4E6EB;text-align:center;clear:both;font-size:10px;font-style:italic;padding:5px 0;">
<a href="http://coinmarketcap.com?utm_medium=widget&utm_campaign=cmcwidget&utm_source=&utm_content=nexus" target="_blank" style="text-decoration: none; color: rgb(66, 139, 202);">Powered by CoinMarketCap</a>
</div>
</div>
</div>