【发布时间】:2014-09-24 22:35:41
【问题描述】:
需要从名为“Main”的 DIV 中名为“one_price”的类中获取数据
在下面的 HTML 中,我需要从代码中返回(2.50 英镑)
我已经尝试过 $('main').find('.one_price') 但似乎无法通过这种方法获得类内部的任何想法
<div id="main">
<div class="product-column one-column right_col">
<div class="product-box">
<div class="product-box-section">
<span class="product_price">
<span class="product_price_values">
<span class="price_title one_price_title">Price: </span>
<span class="one_price">£2.50</span>
<span id="product_rrp">
Was <span class="strikethrough">£7.00</span>
</span>
</span>
<span id="product_saving">
<span id="you_save">
<em class="hd">Save</em>
<em class="percentage val">64%</em>
<em class="currency val">£4.50</em>
</span>
</span>
</span>
</div>
【问题讨论】:
-
您没有具有
id或class的'main'的元素。你期望它匹配什么,准确地说? -
现在用 DIV ID 更新代码
-
谢谢你,现在:“[不能使用]这个,因为页面上有多个
.one_price类[元素]”。您能否提供更具包容性的 DOM 摘录?向我们展示它的样子?你想得到什么具体的结果? -
我到底为什么要关注一个模糊的 URL?您可以在 cmets 中玩 600 个角色:随意使用它们,它们是免费的!并且你需要将该页面的HTML缩减为Minimal, Complete, Verified Excample code并将该代码发布到here,否则这个问题以后对其他人毫无用处。
-
var price = $('#main').find('.one_price').text();工作我搞砸了console.log。感谢您的帮助