Javascript 未捕获类型错误:无法设置属性';价值';Google Chrome中未定义的

Javascript 未捕获类型错误:无法设置属性';价值';Google Chrome中未定义的,javascript,html,google-chrome,Javascript,Html,Google Chrome,在我的页面A中,有一个文本区域定义如下: <textarea readonly wrap="Physical" cols="50" rows="2" name="Attr"> 这会导致Google Chrome中出现错误(错误:“UncaughtTypeError:无法设置未定义的属性“value”),但可以与Internet Explorer和Mozilla Firefox完美配合。我已经阅读了文档。所有的都是旧的,应该用文档.getElementById替换,但没有成功(错误:

在我的页面A中,有一个文本区域定义如下:

<textarea readonly wrap="Physical" cols="50" rows="2" name="Attr">
这会导致Google Chrome中出现错误(错误:“UncaughtTypeError:无法设置未定义的属性“value”),但可以与Internet Explorer和Mozilla Firefox完美配合。我已经阅读了
文档。所有的
都是旧的,应该用
文档.getElementById
替换,但没有成功(错误:“未捕获的TypeError:无法设置null的属性“值”)

如果我用
document.forms[0]
替换
document.all
,它可以在包括谷歌浏览器在内的所有浏览器中工作。但这似乎不是一个好的解决方案,因为除了a页之外,B页可以被其他页调用,并且可能有多个表单

谁能告诉我我做错了什么

提前谢谢


欧佩克。

为什么你不能给它分配一个id,然后通过它访问它

<textarea id="text" readonly wrap="Physical" cols="50" rows="2" name="Attr">
是JSFIDLE在演示它吗

<textarea id="text" readonly wrap="Physical" cols="50" rows="2" name="Attr">
document.getElementById("text").value="Value 1, value 2"