<分区>
我试图在 innerHTML 中创建 when a href,但出现错误或无法正常工作。我想从API制作一个数据,可以点击而不是复制并将其放入浏览器。当我尝试代码时,它将变成 +item.title 而不是转到我从我的 API 获取数据的链接。
<html>
<head>
<title>JSON/Atom Custom Search API Example</title>
</head>
<body>
<div id="content"></div>
<script>
function hndlr(response) {
for (var i = 0; i < response.items.length; i++) {
var item = response.items[i];
// in production code, item.htmlTitle should have the HTML entities escaped.
document.getElementById("content").innerHTML +="<br>"+ item.title + "<br>" +"<a href='+item.title'>Google</a>" ;
}
}
</script>
<script src="https://www.googleapis.com/customsearch/v1?q=query&cx=004123968310343535430%3Aaxml6iel9yo&key=AIzaSyDxPcphnrcN9_dfkRkFTbwkv44m1-HI1Hg&callback=hndlr">
</script>
</body>
</html>