我的 HTML
<div class="product">
<img src="#">
<div class="priceStore">
<p data="40">Item 1</p>
</div>
</div>
如何使用 jQuery 检索数据并存储它?
我的尝试:
$('.product').mousedown(function(event) {
var x = $('.priceStore').parent().find(data);
console.log(x);
});
谢谢!
最佳答案
有几种不同的方法来编写选择器,但要获取属性的值,您可以使用 .attr()
类似的东西适用于这种情况
$('.product').mousedown(function(event) {
var x = $('.priceStore p').attr('data');
console.log(x);
});
关于javascript - 如何从 html 中查找数据并使用 jQuery 存储它,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34621933/