我得到的html内容如下:
var test='<div id="test">Raj</div>';
Run Code Online (Sandbox Code Playgroud)
如何使用javascript从上面的html内容中检索值Raj.
听起来你正试图"Raj"从那个HTML片段中提取文本?
让浏览器的HTML解析器为您做脏工作:
// create an empty div
var div = document.createElement("div");
// fill it with your HTML
div.innerHTML = test;
// find the element whose text you want
test = div.getElementById("test");
// extract the text (innerText for IE, textContent for everyone else)
test = test.innerText || test.textContent;
Run Code Online (Sandbox Code Playgroud)
或者在jQuery中:
test = $(test).text();
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2533 次 |
| 最近记录: |