将Javascript变量放入innerHTML代码中 [英] Put a Javascript variable into a innerHTML code
本文介绍了将Javascript变量放入innerHTML代码中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在用Javascript创建一个表动态表:
I'm creating a table dynamic table with Javascript:
var row = table.insertRow(-1);
var cell1 = row.insertCell(0);
var cell2 = row.insertCell(1);
var cell3 = row.insertCell(2);
var cell4 = row.insertCell(3);
var cell5 = row.insertCell(4);
我想用一些带有Javascript变量的innerHTML填充cell5
I want to fill the cell5 with some innerHTML with a Javascript variable inside
var add = aux[i].split("#");
cell5.innerHTML = "<img src='MatrixLogos/add[3]' width='100' height='25'/>";
但这会在html中添加[3]而不是add [3]中的值。
but this give add[3] in the html instead of the value inside add[3].
我的问题是如何在innerHTML代码中转义变量,所以它显示的是值而不是声明。
My question is how to escape the variable inside the innerHTML code, so it shows me is value and not the declaration.
推荐答案
使用+。
var add = aux[i].split("#");
cell5.innerHTML = "<img src='MatrixLogos/"+add[3]+"' width='100' height='25'/>";
这篇关于将Javascript变量放入innerHTML代码中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文