在JS中解析HTML字符串示例代码
时间:2024-04-19 11:02:47
在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>
在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
标签:HTML,字符串
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
selenium+python设置爬虫代理IP的方法
2021-10-01 11:14:33
Symfony控制层深入详解
2023-11-14 20:43:33
![](https://img.aspxhome.com/file/2023/6/92806_0s.png)
oracle 日期函数
2010-07-23 13:32:00
Design IT. (3),看不懂数据
2009-02-11 10:56:00
python实现beta分布概率密度函数的方法
2021-08-02 21:39:16
![](https://img.aspxhome.com/file/2023/9/93449_0s.jpg)
PHP实现向关联数组指定的Key之前插入元素的方法
2023-07-14 08:41:33
一个asp版的xheditor上传图片服务器端文件
2009-12-21 14:18:00
![](https://img.aspxhome.com/file/UploadPic/20101/11/200982514518-20s.jpg)
python中defaultdict的用法详解
2021-05-02 11:11:07
MAC下Mysql5.7.10版本修改root密码的方法
2024-01-27 00:05:58
PyCharm配置KBEngine快速处理代码提示冲突、配置命令问题
2023-08-12 09:14:28
![](https://img.aspxhome.com/file/2023/4/64654_0s.png)
Linux下彻底卸载mysql详解
2024-01-13 11:31:50
![](https://img.aspxhome.com/file/2023/8/69868_0s.jpg)
Python高级编程之继承问题详解(super与mro)
2023-08-08 18:58:47
![](https://img.aspxhome.com/file/2023/1/62281_0s.png)
Python语言实现SIFT算法
2022-12-30 17:58:14
![](https://img.aspxhome.com/file/2023/6/97626_0s.png)
ASP网站数据采集经验谈
2008-03-09 15:30:00
python去除字符串中的空格、特殊字符和指定字符的三种方法
2022-06-12 20:21:31
![](https://img.aspxhome.com/file/2023/4/106984_0s.jpg)
在python中使用正则表达式查找可嵌套字符串组
2021-10-07 07:02:06
uni-app网络请求、数据缓存实例详解
2023-08-09 03:49:12
新 API 寻求让 JavaScript 操作本地文件
2009-11-27 18:28:00
![](https://img.aspxhome.com/file/UploadPic/200911/27/2g33954gi_lit-43s.gif)
vue之prop与$emit的用法说明
2024-05-09 15:20:41
老生常谈进程线程协程那些事儿
2021-01-19 19:47:57
![](https://img.aspxhome.com/file/2023/4/105644_0s.jpg)