js 获取data-属性值


// html code
<span class="1pc_price" data-price="<?php echo Country::change('$29.95',$money_type) . "<br/>Download Instantly"; ?>"></span>

// js code
var
price_1pc_hb = document.getElementsByClassName('1pc_price')[0].getAttribute('data-price');

 注意

document.getElementsByClassName('1pc_price')后面有[0],不然会报错。
原文地址:https://www.cnblogs.com/ryanzheng/p/9037240.html