什么引起了这个错误?我应该传递element.value到函数中吗?我知道如何在JSP中设置,而不是在JavaScript中。我无法将值传递给另一个函数。'value.length'为空或不是对象
function editCommentToggle(id)
{
theRow = document.getElementById("id"+id);
//user = theRow.cells[0].innerHTML;
//date = theRow.cells[1].innerHTML;
com = theRow.cells[2].innerHTML;
idx = 2;
maxlength = 250;
// Comment field
cell = theRow.cells[idx];
while(cell.childNodes.length > 0)
cell.removeChild(cell.childNodes[0]);
element = document.createElement("textarea");
element.id="comments-"+id;
element.rows="3";
element.value = com;
element.style.width = "400px";
element.maxLength = "250";
element.onfocus = element.onkeydown = element.onkeyup = function(){
return characterCounterEdit(undefined, maxlength, element);
};
cell.appendChild(element);
function characterCounterEdit(id, maxLen, inputElement)
{
spanId = document.getElementById(id);
if (spanId)
{
// Update the counter the user sees.
var whatIsLeft = maxLen - inputElement.value.length;
if (whatIsLeft < 0) whatIsLeft = 0;
spanId.innerText = whatIsLeft;
}
// Restrict user from entering more than the maxlen.
**ERROR HERE-->>>** if (inputElement.value.length > maxLen)
{
inputElement.value = inputElement.value.substring(0, maxLen);
}
}
你的问题是什么?你有什么尝试?我们不是一个自动化的代码调试机器。 –
我尝试在函数中传递“元素”本身 –
请回答一个问题,最好由至少几个英文句子组成。最好用一些小心谨慎的句子,而不是少量的拼写错误和缺乏标点符号! –