我有解析javascript的问题。我想输出标题永久链接的值和标记为" image_01"的基本名称的值。因此它只会输出http://blog.url/news/images/201516.jpg
<div id="placeholder"></div>
<script>
var data={
"items": [
{
"title": "HELLO THIS IS TITLE",
"customFields": [
{
"basename": "image_01",
"value": "<form mt:asset-id=\"352706\" class=\"mt-enclosure mt-enclosure-image\" style=\"display: inline;\"><a href=\"http://blog.url/news/images/201516.jpg\">201516.jpg<\/a><\/form>"
},
{
"basename":"image_02",
"value":"<form mt:asset-id=\"352705\" class=\"mt-enclosure mt-enclosure-image\" style=\"display: inline;\"><a href=\"http://blog.url/news/images/201516.jpg\">201517.jpg<\/a><\/form>"
},
{
"basename":"image_03",
"value":""
},
],
"permalink": "http://blog.com/index.php"
}
]
}
document.getElementById("placeholder").innerHTML=data.items[0].title + " " + data.items[0].permalink+"--"+ data.items[0].customFields[0].basename[0].image_01;
</script>
答案 0 :(得分:0)
所以用customFields [0] .value属性替换customFields [0] .basename [0] .image_01,该属性的图像路径为basename,标记为“image_01”。
document.getElementById("placeholder").innerHTML=data.items[0].title + " " + data.items[0].permalink+"--"+ data.items[0].customFields[0].value;
答案 1 :(得分:0)
我认为@Kanti给出了正确答案,你可以更具体:
document.getElementById("placeholder").innerHTML=data.items[0].title + " " + data.items[0].permalink+"--"+ data.items[0].customFields[0].basename;