Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/400.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在使用Javascript创建按钮时包含变量?_Javascript_Variables - Fatal编程技术网

如何在使用Javascript创建按钮时包含变量?

如何在使用Javascript创建按钮时包含变量?,javascript,variables,Javascript,Variables,我通过添加以下代码,从javascript for循环动态创建按钮 var container = document.getElementById('myList'); var new_element = document.createElement('li'); new_element.innerHTML = '<button type="button" id="">label</button>'; 如何将这些数组值括在创建按钮的字符串中?newElement.inn

我通过添加以下代码,从javascript for循环动态创建按钮

var container = document.getElementById('myList');
var new_element = document.createElement('li');
new_element.innerHTML = '<button type="button" id="">label</button>';
如何将这些数组值括在创建按钮的字符串中?

newElement.innerHTML=''+arrMarkers[I].title+'';
newElement.innerHTML = '<button type="button" id="' + arrMarkers[i].id + '">' + arrMarkers[i].title + '</button>';

据我所知,您正在寻找字符串连接:

new_element.innerHTML = '<button type="button" id="' + arrMarkers[i].id + '">' + arrMarkers[i].title + '</button>';
new_element.innerHTML=''+arrmakers[i].title+'';

有什么问题?这是一个常见的concate
“标签”你们在那个里找到按钮了吗。。。??据我所知,你不会得到任何按钮
:D
谁不喜欢字符串串联?不知道为什么这个答案被否决。有人能给我解释一下吗?也许这太简单了,视觉无法回答…:)。如果值得投票,为什么不投票呢。并投反对票meaningless@RabNawaz哈很抱歉,答案很简单。
:)非常欢迎您,即使是总分。
;)
new_element.innerHTML = '<button type="button" id="' + arrMarkers[i].id + '">' + arrMarkers[i].title + '</button>';