后台返回的js字符串或html字符串禁止解析
在js中直接添加html语句,js会将html字符串解析成相应的HTML语句,并在前端进行显示。
代码如下:
<span style="font-size:14px;">var el = document.createElement( 'div' );
el.innerHTML
=
"<html><head><title>titleTest</title></head><body><a
href='test0'>test01</a><a
href='test1'>test02</a><a
href='test2'>test03</a></body></html>";
el.getElementsByTagName( 'a' ); // Live NodeList of your anchor elements</span>
2.在jquery中进行应用:
代码如下:
var el = $( '<div></div>' );
el.html("<html><head><title>titleTest</title></head><body><a
href='test0'>test01</a><a
href='test1'>test02</a><a
href='test2'>test03</a></body></html>");
$('a', el) // All the anchor elements