【问题标题】:How to add an image in a function on javascript如何在javascript的函数中添加图像
【发布时间】:2014-09-30 13:03:09
【问题描述】:

您好,我在 java 脚本中有一个函数,其中包含一些文本,但现在我也想添加图像。

如何在函数内插入图片?

这是 JAVASCRIPT 代码:

<script type="text/javascript">
function CONshowElements(){
        var Construction = "The construction company with several years of experience in projects valued over millions of USD having Service and Quality with satisfaction and appreciation of the clients";

       document.getElementById("contents").innerHTML = Construction;
       var image = new Image;
      image.src = "images/SCALE Construction.png";
          }
      </script>

正文代码

  <a href="construction.php"><div class="firstbox" id="Construction" onmouseover="CONshowElements(); return false; " >Construction</div></a>

【问题讨论】:

标签: javascript


【解决方案1】:

也许你想要这个答案:

function CONshowElements(){
   var img = document.createElement("img");
   img.setAttribute("src","images/SCALE Construction.png");
   document.body.appendChild(img);
   return false;
}
document.getElementById("Construction").onclick = CONshowElements;

查看:http://jsfiddle.net/yuanzm/x0zs7gb1/

【讨论】:

    【解决方案2】:

    您只想将图像移动到var Construction,这样就可以了

    var Construction = 'The construction company with several years of experience in projects valued over millions of USD having Service and Quality with satisfaction and appreciation of the clients <img src="images/SCALE Construction.png">';
    

    【讨论】:

      猜你喜欢
      • 2015-04-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-08-08
      • 1970-01-01
      • 2022-07-04
      相关资源
      最近更新 更多