创建的元素添加事件处理函数(带参数)在下面的函数中,我试图创建一个动态元素(textArea)。我试图使用将文本区域(调整大小)绑定到文本区域textArea.onclick = resize;这工作正常。向使用document.createElement
我希望做的是,如果我说textArea.onclick =调整参数传递给调整大小功能(无论是生成的ID或者,如果可能的话,textarea的本身),
function addElement(elm, event) {
var textArea = document.createElement('textarea');
var id = Math.random();
textArea.setAttribute('id', id)
textArea.setAttribute('cols', 1);
textArea.setAttribute('rows', 3);
textArea.onclick = resize;
elm.appendChild(textArea);
}
( ID);然后只是调用该函数。
我该如何绑定函数,并将参数传递给它?