javascript - 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>';
解决方案
您的代码中似乎有很多错别字。
请参阅下面的工作代码。
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);
推荐阅读
- kubernetes - config.lock 上的 Kubernetes 权限被拒绝错误
- javascript - 如何为`设置静态SVG大小
` 下的元素 - annotations - 定义openapi/swagger注解的常用参数
- python - 实体 - DialogFlow 中的文本到编号
- formatting - 将字符串中的所有数值相乘时格式化十进制输出?
- javascript - ng-option 在第一次调用时不选择模型值
- sapui5 - 如何从外部访问组件模型
- ruby - Slim:方法调用中的注释语法
- scsi - 物理驱动器上 SCSI 读取 (10) 的最大传输大小
- javascript - yup.js 条件时检查数组