【发布时间】:2020-05-20 14:09:15
【问题描述】:
这是我的 JSON 的一个对象:
{
"box": [
{
"htm": "<div style=\"float:left;margin:0 0 10px\"><img alt=\"BICYCLE GARAGE\" src=\"//cdn.membershipworks.com/u/5ceef04cf033bfad7c9d9c82_lgl.jpg?1565140260\" class=\"SFbizlgo\" onerror=\"SF.del(this)\"></div><div style=\"float:left\"><h1 style=\"display:block;margin:0;padding:0;\">BICYCLE GARAGE</h1><p style=\"margin:15px 0 0;\">"For bicycling around the block or around the world" Bloomington, Indiana</p></div><div style=\"clear:both;\"></div>"
}
],
"lbl": "About"
}
],
为了得到我所做的盒子对象
const logoHtml = tpl[0].box[0].htm
在我的控制台中,我收到了<div style="float:left;margin:0 0 10px"><img alt="ALAMEDA BICYCLE" src="//cdn.membershipworks.com/u/5ceef04bf033bfad7c9d9c0a_lgl.jpg?1566946141" class="SFbizlgo" onerror="SF.del(this)"></div><div style="float:left"><h1 style="display:block;margin:0;padding:0;">ALAMEDA BICYCLE</h1><p style="margin:15px 0 0;"></p></div><div style="clear:both;"></div>
哪个好!为了获得我一直在做的 src 属性const newLogo = document.getElementsByTagName('img').src
现在,如何结合这两个常量来从 img 标签中获取 src 属性?
【问题讨论】:
-
^ 解析页面 sn-p 使用
document.createElement("div")而不是document.createElement("html")。
标签: javascript html arrays json reactjs