我正在尝试学习 JavaScript 中的正则表达式解析。
我需要在“跨度”内阅读文本
<span class="item_color_title">Status:</span>
<span class="item_color_success">
Alive
</span>
“活着”就是我所需要的。有什么简单的出路吗?
这是一个 Firefox 扩展,我已经:
var req = new XMLHttpRequest();
req.open('GET', 'http://www.example.com/', false);
req.send(null);
if(req.status == 200)
standard_status.label = req.responseText;
而且,standard_status 应该显示“Alive”
谢谢!!
最佳答案
将响应解析为 HTML 片段:
> html = $('<div/>').html(req.responseText)
> $('.item_color_success', html).text()
"Alive"
关于javascript html 正则表达式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9590010/