通过javascript转换小于和大于标记& lt和& gt的html [英] convert html less than and greater than tags &lt and &gt through javascript
本文介绍了通过javascript转换小于和大于标记& lt和& gt的html的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我如何转换<和>使用javascript
how i can convert < and > html tags using javascript
推荐答案
的html标签我不确定您是否需要此标签.相反,您可以使用DOM操作HTML.请参见,例如:
http://stackoverflow.com/questions/3905310/is-there-a-javascript-equivelent-of-htmlencode-htmldecode-from-asp-net [
I''m not sure you if ever need this. Instead, you can manipulate HTML using DOM. Please see, for example:
http://stackoverflow.com/questions/3905310/is-there-a-javascript-equivelent-of-htmlencode-htmldecode-from-asp-net[^].
—SA
尝试以下功能:
Try this function:
function htmlencode(str) {
return str.replace(/[&<>"']/g, function(
0){ 返回"& + {"& :" amp , "< :" lt ,"> :" gt " ' :","' " #39 "
0) { return "&" + {"&":"amp", "<":"lt", ">":"gt", '"':"quot", "'":"#39"}
这篇关于通过javascript转换小于和大于标记& lt和& gt的html的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文