getElementById在IE中找到一个元素,但不是Firefox [英] getElementById finds an element in IE but not Firefox

查看:68
本文介绍了getElementById在IE中找到一个元素,但不是Firefox的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,


以下代码适用于IE但不适用于Firefox。 IE产生

预期这是更多文字!输出,但Firefox产生没有更多

文本。有什么想法吗?


< BODY>

< FORM>

< INPUT TYPE = HIDDEN NAME =" moreText" VALUE ="< PRE>这是更多

text!< / PRE>">

< SCRIPT LANGUAGE =" javascript">

var m =(document.getElementById&&

document.getElementById(''moreText''))

? document.getElementById(''moreText'')。value

:''< PRE>不再有文字< / PRE>'';

document.writeln(m );

< / SCRIPT>

< / FORM>

< / BODY>


仅供参考,我已经尝试了表格内外的脚本,

和代码表现相同。


谢谢!

-Dave H.

Hi All,

The following code works in IE but not Firefox. IE produces the
expected "this is more text!" output, but Firefox produces "no more
text". Any ideas why?

<BODY>
<FORM>
<INPUT TYPE=HIDDEN NAME="moreText" VALUE="<PRE>This is more
text!</PRE>">
<SCRIPT LANGUAGE="javascript">
var m = (document.getElementById &&
document.getElementById(''moreText''))
? document.getElementById(''moreText'').value
: ''<PRE>no more text</PRE>'';
document.writeln(m);
</SCRIPT>
</FORM>
</BODY>

FYI, I''ve tried it with the script both within and outside the form,
and the code behaves identically.

Thanks!
-Dave H.

推荐答案

Dave Hammond于2005年5月15日在comp.lang.javascript上写道b> :
Dave Hammond wrote on 15 feb 2005 in comp.lang.javascript:
< SCRIPT LANGUAGE =" javascript">
var m =(document.getElementById&&
文档.getElementById(''moreText''))
? document.getElementById(''moreText'')。value
:''< PRE>不再有文字< / PRE>'';
document.writeln(m);
< / SCRIPT>
<SCRIPT LANGUAGE="javascript">
var m = (document.getElementById &&
document.getElementById(''moreText''))
? document.getElementById(''moreText'').value
: ''<PRE>no more text</PRE>'';
document.writeln(m);
</SCRIPT>




当页面已经加载时,你无法在

屏幕上执行document.write()而不会破坏整个页面,包括javascript。


尝试DOM插入(innerHTML或子)到< div>


-

Evertjan。

荷兰。

(用我的电子邮件地址替换所有带点的十字架)



You cannot do a document.write() when the page is already loaded and on
screen without destroying the whole page, including the javascript.

Try DOM-inserting (innerHTML or child) to a <div>

--
Evertjan.
The Netherlands.
(Replace all crosses with dots in my emailaddress)

Dave Hammond写道:
Dave Hammond wrote:
大家好,

以下代码适用于IE但不适用于Firefox。 IE产生
预期的这是更多文本!输出,但Firefox生成没有更多的文本。任何想法为什么?

< BODY>
< FORM>
< INPUT TYPE = HIDDEN NAME =" moreText" VALUE ="< PRE>这是更多
文字!< / PRE>">
< SCRIPT LANGUAGE =" javascript">
var m =(document .getElementById&&
document.getElementById(''moreText''))
? document.getElementById(''moreText'')。value
:''< PRE>不再有文字< / PRE>'';
document.writeln(m);
< / SCRIPT>
< / FORM>
< / BODY>

仅供参考,我已经尝试过表格内外的剧本,并且代码行为相同。

谢谢!
-Dave H.
Hi All,

The following code works in IE but not Firefox. IE produces the
expected "this is more text!" output, but Firefox produces "no more
text". Any ideas why?

<BODY>
<FORM>
<INPUT TYPE=HIDDEN NAME="moreText" VALUE="<PRE>This is more
text!</PRE>">
<SCRIPT LANGUAGE="javascript">
var m = (document.getElementById &&
document.getElementById(''moreText''))
? document.getElementById(''moreText'').value
: ''<PRE>no more text</PRE>'';
document.writeln(m);
</SCRIPT>
</FORM>
</BODY>

FYI, I''ve tried it with the script both within and outside the form,
and the code behaves identically.

Thanks!
-Dave H.




getElementById(作为其name implies)找到一个具有匹配的

ID属性的元素。 Windows上的IE浏览器也会找到具有匹配的NAME

属性的元素,但这是非标准的。



The getElementById (as its name implies) finds an element with a matching
ID attribute. IE on windows will also find elements with a matching NAME
attribute, but this is non-standard.


Dave Hammond写道:
Dave Hammond wrote:
以下代码适用于IE但不适用于Firefox。
[...]
< INPUT [...] NAME =" moreText" [...]>
~~~~ [...]
document.getElementById(''moreText'')
~~~~ [...]
The following code works in IE but not Firefox.
[...]
<INPUT [...] NAME="moreText" [...]> ~~~~ [...]
document.getElementById(''moreText'') ~~~~ [...]




仅在MSIE中,name和id属性共享一个命名空间。

只需添加一个id =" moreText"属性为输入元素。


ciao,dhgm



In MSIE only, name and id attributes share one namespace.
Simply add an id="moreText" attribute to the input element.

ciao, dhgm


这篇关于getElementById在IE中找到一个元素,但不是Firefox的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆