不确定此代码有什么问题。我一直收到以下错误:
“语法错误”
“预期的对象”:''style.cssText'为null或不是对象“
这就是我得到的:
function doSomething()
{
var textarea = document.getElementsByName("mcRemarkOld");
turnTextAreaIntoDiv(textarea);
}
function turnTextAreaIntoDiv(elem)
{
var div = document.createElement("div"); // Copy significant attributes, customize.
div.className = elem.className;
div.style.cssText = elem.style.cssText; <<<<<<---''style.cssText' is null or not an object
div.id = elem.id;
div.name = elem.name; <<----SYNTAX ERROR HERE
div.innerHTML = elem.innerHTML; //`<a>` turns in <a>
elem.parentNode.replaceChild(div, elem);
}
</script>
<body onload="javascript:doSomething()">
<TEXTAREA class="textarea_readonly" readonly="readonly" name="mcRemarkOld" rows="7" cols="100" scrolling="auto"> <c:forEach var="mcbean" items="${form.mcRemarks}">--- ${mcbean.auditable.createdBy.firstName} ${mcbean.auditable.createdBy.lastName}, <fmt:formatDate value="${mcbean.auditable.createdDate}" pattern="${date_time_pattern}" />
${mcbean.remark} --- <a href="show.view_hotparts_guidelines?id=${mcbean.id}">TEST!!!!!!</a>
</c:forEach></TEXTAREA><br/>
答案 0 :(得分:2)
变量是一个元素数组
var textarea = document.getElementsByName("mcRemarkOld");
尝试使用:
var textarea = document.getElementsByName("mcRemarkOld")[0];
或
var textarea = document.getElementByName("mcRemarkOld");