Javascript 如何将多个函数组合成一个函数?

Javascript 如何将多个函数组合成一个函数?,javascript,html,function,for-loop,Javascript,Html,Function,For Loop,我有一个带循环的动态按钮,还有onclick属性函数,如下所示: for (var j=0; j<= 1; j++){ btndisplay= document.createElement("input"); btndisplay.setAttribute("type", "button"); btndisplay.setAttribute("style","height:80px;width:60px"); btndisplay.setAttribute("onclic

我有一个带循环的动态按钮,还有onclick属性函数,如下所示:

for (var j=0; j<= 1; j++){ 
  btndisplay= document.createElement("input");
  btndisplay.setAttribute("type", "button");
  btndisplay.setAttribute("style","height:80px;width:60px");
  btndisplay.setAttribute("onclick", "myFunction"+ (j+1) +"(this.name)"); 
  document.getElementById('divButtons'+(j+1)).appendChild(btndisplay);   
}

使用另一个参数,一个用于
名称
,另一个用于
标识

function myFunction(id, name) 
{
    if ( document.getElementById(id).innerHTML=="" )
        document.getElementById(id).innerHTML = name; 
}
您已创建:

<input type="button" onclick="myFunction(this)">
<input...
...
<input type="button" onclick="myFunction(this)">
<input...
...
function myFunction (that) {
  if(that.innerHTML === "") {
    that.innerHTML = that.name;
  }
}