好的,这可能很容易,我只是不知道该怎么做。我有一个主要功能,它接受一个“id”。这个 id 是唯一的,我想将它传递给另一个正在为我进行计数的函数,并将该计数返回给 innerHtml 跨度标记。
这样做的原因是因为我可以同时打开其中的 5 个,但它们将具有相同的跨度 id 名称“editCommentsCounter”......我希望它们像“editCommentsCounter-id”
function editCommentToggle( id )
{
theRow = document.getElementById("id"+id);
//user = theRow.cells[0].innerHTML;
//date = theRow.cells[1].innerHTML;
com = theRow.cells[2].innerText ;
comLength = theRow.cells[2].innerText.length ;
idx = 2;
maxlength = 250;
count = maxlength - comLength;
// Comment field
cell = theRow.cells[idx];
while( cell.childNodes.length > 0 ) cell.removeChild(cell.childNodes[0]);
spanTag = document.createElement("span");
spanTag.innerHTML = "You have <strong><span id='editCommentsCounter'>"+count+"</span></strong> characters left.<br/>";
cell.appendChild(spanTag);
element = document.createElement("textarea");
element.id="commentsTextArea-"+id;
element.rows="3";
element.value = com;
element.style.width = "400px";
element.maxLength = "250";
element.onfocus = element.onkeydown = element.onkeyup = function(){return characterCounterEdit('editCommentsCounter', maxlength, this);};
cell.appendChild(element);
}
基本上我想采取:
spanTag.innerHTML = "You have <strong><span id='editCommentsCounter'>"+count+"</span></strong> characters left.<br/>";
并将其变成类似 `span id='editCommentsCounter-' + id
所以当我这样称呼时:
element.onfocus = element.onkeydown = element.onkeyup = function(){return characterCounterEdit('editCommentsCounter', maxlength, this);};
我在上面使用带有该 ID 的 editCommentsCounter 调用它
看看我在说什么?