gpt4 book ai didi

javascript - 使用 jquery 从文本区域解析 HTML

转载 作者:行者123 更新时间:2023-11-30 21:16:09 25 4
gpt4 key购买 nike

我想从文本区域解析一些 html 内容,并使用 jquery 从选定的标签中获取值。我尝试了下面的代码,但没有希望。

var a = $('#a').val();
var dom_nodes = $($.parseHTML(a));
alert(dom_nodes.find('#ae').html());
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<textarea id="a">
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html>
<html b:version='2' class='v2' expr:dir='data:blog.languageDirection' xmlns='http://www.w3.org/1999/xhtml' xmlns:b='http://www.google.com/2005/gml/b' xmlns:data='http://www.google.com/2005/gml/data' xmlns:expr='http://www.google.com/2005/gml/expr'>
<b:if cond='data:skin.vars.body_background.image and data:features.responsiveBackgrounds' id='ae'>
<b:with value='&quot;body&quot;' var='selector'>
<b:include cond='not data:view.isPreview' data='skin.vars.body_background.image' name='responsiveImageStyle'/>
</b:with>
</b:if>
</html>
</textarea>

最佳答案

改用parseXML

var a = $('#a').val();
var dom_nodes = $($.parseXML(a));
alert(dom_nodes.find('#ae').html());
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<textarea id="a">
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html>
<html b:version='2' class='v2' expr:dir='data:blog.languageDirection' xmlns='http://www.w3.org/1999/xhtml' xmlns:b='http://www.google.com/2005/gml/b' xmlns:data='http://www.google.com/2005/gml/data' xmlns:expr='http://www.google.com/2005/gml/expr'>
<b:if cond='data:skin.vars.body_background.image and data:features.responsiveBackgrounds' id='ae'>
<b:with value='&quot;body&quot;' var='selector'>
<b:include cond='not data:view.isPreview' data='skin.vars.body_background.image' name='responsiveImageStyle'/>
</b:with>
</b:if>
</html>
</textarea>

关于javascript - 使用 jquery 从文本区域解析 HTML,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45663739/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com