Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如果我有这样的html:
<td>Something here<span>spanText</span></td>
使用 jquery 的 html 方法,我只想获取跨度文本而不是整个内容。所以这是我的jQuery代码:
var data = $(this).html();
这使得:
data = Something here; spanText
但我希望数据是:
data = spanText
那么有没有办法让 html 方法只抓取跨度文本而不是整个东西?
这个怎么样?
var data = $("span", this).html();
var spanText = $(this).find('span').text();