如何在javascript中将变量放入innerHTML标记内?

时间:2017-07-12 07:45:17

标签: javascript

var item = document.getElementById('drpItem').value;
var createDiv = document.createElement('createDiv');

createDiv.className = 'row';

createDiv.innerHTML = '<input type="text" name="name" value="item" />

1 个答案:

答案 0 :(得分:1)

试试这样。'string'+variable+'string'

createDiv.innerHTML = '<input type="text" name="name" value="'+item+'" />