什麼引起了這個錯誤?我應該傳遞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);
}
}
你的問題是什麼?你有什麼嘗試?我們不是一個自動化的代碼調試機器。 –
我嘗試在函數中傳遞「元素」本身 –
請回答一個問題,最好由至少幾個英文句子組成。最好用一些小心謹慎的句子,而不是少量的拼寫錯誤和缺乏標點符號! –