首页 > 解决方案 > How to add an href and img tag via JavaScript

问题描述

The problem I have is when I put a href link in javascript and also img tag, the image won't display.

html='<div id="iw-container">'+'<a ><div class="iw-title">Hot Pot Restaurant </div> </a>'+ name+"<br>"+address+"<br>"+"<img src=/"+image+'</div>';

标签: javascriptphphtml

解决方案


您的代码中似乎有很多错别字。

请参阅下面的工作代码。

let address = 'An Address';
let name = 'Persons Name';
let image = 'https://images.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png';
let link = 'https://images.google.com/';

html='<div id="iw-container"><a href="'+link+'"><div class="iw-title">Hot Pot Restaurant </div> </a>'+ name+'<br>'+address+'<br><img src="'+image+'"></div>';

document.write(html);


推荐阅读