我想将javascript变量分配给javascript内部的html元素 [英] I want to assign javascript variable to html element inside javascript

查看:67
本文介绍了我想将javascript变量分配给javascript内部的html元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在html元素中插入javascript变量值,但是它不能正常工作..以下是我的代码。

I'm trying to insert javascript variable value in html element inside javascript.. But it's not working properly.. following are my code..

 window.onload = function() {
    var image=document.getElementById('img').value;
        var img = '<div id="pic"><img src="image" width="200" height="108" /><p></p></div>';
      }

这是函数。在这里,我得到的图像在变量图像..我想分配此图像在一个div id图片..那里我分配src =图像,我得到了var图像..但它不工作。 。

This is the function. Here i'm getting image in variable image.. i'm trying to assign this image to in one div id pic.. there i'm assigning src="image" which i got in var image.. But its not working..

推荐答案

您需要将值插入到字符串中:

You need to insert the value into the string:

var img = '<div id="pic"><img src="' + image + '" width="200" height="108" /><p></p></div>';

这篇关于我想将javascript变量分配给javascript内部的html元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆