.val() get text with html tags? Maybe .text(), but how to do this correctly?
.val()获取带有html标签的文本?也许.text(),但如何正确地做到这一点?
1 个解决方案
#1
1
var el = document.getElementById(elementId); // or just another HTML DOM element
var text = el.innerHTML.replace(/<[^>]+>/g, "");
might do something close to what you want.
可能会做一些接近你想要的事情。
EDIT: This is what it does on Stack Overflow:
编辑:这是它在Stack Overflow上的作用:
document.getElementById("portalLink").innerHTML.replace(/<[^>]+>/g, "")
in Chrome's Console yields
在Chrome的控制台收益率
"
Stack Exchange
"
#1
1
var el = document.getElementById(elementId); // or just another HTML DOM element
var text = el.innerHTML.replace(/<[^>]+>/g, "");
might do something close to what you want.
可能会做一些接近你想要的事情。
EDIT: This is what it does on Stack Overflow:
编辑:这是它在Stack Overflow上的作用:
document.getElementById("portalLink").innerHTML.replace(/<[^>]+>/g, "")
in Chrome's Console yields
在Chrome的控制台收益率
"
Stack Exchange
"