且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

undefined getElementById

更新时间:2023-11-27 13:41:58


为什么

var offer = document.getElementById(" editor_displaying_t ext") .value;

返回undefined?

谢谢
Why
var offer=document.getElementById("editor_displaying_t ext").value;
returns undefined?
Thank You



如果没有知识真的很难说什么是editor_displaying_text是。


我要继续说不是所有元素都有一个名为value的属性......事实上,大多数元素都没有。除非editor_displaying_text是OBJECT,PARAM,LI,INPUT是对象。或BUTTON,值将返回undefined。


阅读DTD:http://www.w3.org/TR/html/DTD/xhtml1-transitional.dtd,对值执行CTRL-F并且看看它经常出现的频率......不常见。


您可能想查看childNodes。数组中的元素中的dom元素列表 - 或者,如果您喜欢便宜的&简单的出路,innerHTML。

it''s really hard to tell without knowledge of what "editor_displaying_text" is.

I''m going to go on a limb and say not all elements have a property called "value"... in fact, most do not. Unless "editor_displaying_text" is an "OBJECT", "PARAM", "LI", "INPUT" or "BUTTON", value will return undefined.

Read the DTD: http://www.w3.org/TR/html/DTD/xhtml1-transitional.dtd, do a CTRL-F for "value" and see how often it shows up.... not very often.

You may want to check out the "childNodes" array for a list of dom elements within the element -- or, if you like the cheap & easy way out, innerHTML.


这是一个可编辑的div,id是editor_displaying_text

谢谢你
It''s an editable div which id is editor_displaying_text
Thank You


你''必须显示你的代码。你在哪里定义页面?
You''ll have to show your code. Where do you define it within the page?