innerHTML在Firefox中表现不佳? [英] innerHTML not good in Firefox?

查看:73
本文介绍了innerHTML在Firefox中表现不佳?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过点击

按钮更改我的页面中的某些文字。谷歌我发现内部文本

并不适用于每个浏览器,所以我已经切换到了

innerHTML。它适用于IE和Opera,但没有什么

在Firefox上发生(刚刚更新到1.0.4版本)。


有什么建议吗?


提前致谢! C.

....

< script type =" text / javascript">


function changeText( newtext)

{

text.innerHTML = newtext;

}

< / script>


< p id =" text">旧文< / p>

< input type =" button" onclick =" changeText(''New text'')"

value =" change text" />

....

I''m trying to have some text in my page changed by clicking
a button. Googleing around I''ve discovered that innerText
doesn''t work with every browser, so I''ve switched to
innerHTML. It works fine on IE and Opera, but nothing
happens on Firefox (just updated to version 1.0.4).

Any suggestions?

Thanks in advance! C.
....
<script type="text/javascript">

function changeText(newtext)
{
text.innerHTML = newtext;
}
</script>

<p id="text">Old text</p>
<input type="button" onclick="changeText(''New text'')"
value="Change text" />
....

推荐答案

catorcio写道:
catorcio wrote:
我''我试图通过点击按钮改变我的页面中的一些文字。
Google周围我发现innerText并不适用于每个浏览器,所以我已经切换到innerHTML。它在IE和Opera上运行良好,但在Firefox上没有任何反应(只更新到版本1.0.4)。

有什么建议吗?

提前致谢! C.

...
< script type =" text / javascript">

函数changeText(newtext)
{
text.innerHTML = newtext;
}
I''m trying to have some text in my page changed by clicking a button.
Googleing around I''ve discovered that innerText doesn''t work with every
browser, so I''ve switched to innerHTML. It works fine on IE and Opera,
but nothing happens on Firefox (just updated to version 1.0.4).

Any suggestions?

Thanks in advance! C.
...
<script type="text/javascript">

function changeText(newtext)
{
text.innerHTML = newtext;
}




您错过了对段落的引用。在innerHTML之前把这行




var text = document.getElementById(''text'');


HTH



You have missed to get a reference to the paragraph. Put this line
before innerHTML:

var text = document.getElementById(''text'');

HTH




" catorcio" < c@torc.io>在消息中写道

news:d6 ********** @ domitilla.aioe.org ...

"catorcio" <c@torc.io> wrote in message
news:d6**********@domitilla.aioe.org...
我正在试着写一些文字通过单击按钮更改了我的页面。
谷歌周围我发现innerText不适用于每个浏览器,所以我已经切换到innerHTML。它在IE和Opera上工作正常,但是在Firefox上没有任何反应(刚刚更新到1.0.4版本)。

有什么建议吗?

提前致谢! C.



为我工作1.0.3


Jay

...
< script type =" text / javascript">

函数changeText(newtext)
{
text.innerHTML = newtext;
}

< / script>
< p id =" text">旧文< / p>
< input type =" button" onclick =" changeText(''New text'')" value ="更改文字"
/>
...
I''m trying to have some text in my page changed by clicking a button.
Googleing around I''ve discovered that innerText doesn''t work with every
browser, so I''ve switched to innerHTML. It works fine on IE and Opera, but
nothing happens on Firefox (just updated to version 1.0.4).

Any suggestions?

Thanks in advance! C.

Works for me 1.0.3

Jay
...
<script type="text/javascript">

function changeText(newtext)
{
text.innerHTML = newtext;
}
</script>

<p id="text">Old text</p>
<input type="button" onclick="changeText(''New text'')" value="Change text"
/>
...



catorcio写道:
catorcio wrote:
我正在尝试通过单击按钮更改页面中的某些文本。
谷歌周围我发现innerText不适用于每个浏览器,所以我已经切换到innerHTML。它在IE和Opera上运行良好,但在Firefox上没有任何反应(只更新到版本1.0.4)。

有什么建议吗?

提前致谢! C.

....
< script type =" text / javascript">

函数changeText(newtext)
{
text.innerHTML = newtext;
}

< / script>

< p id =" text">旧文< / p>
< input type =" button" onclick =" changeText(''New text'')" value ="更改
文字 />
....
I''m trying to have some text in my page changed by clicking a button.
Googleing around I''ve discovered that innerText doesn''t work with every
browser, so I''ve switched to innerHTML. It works fine on IE and Opera,
but nothing happens on Firefox (just updated to version 1.0.4).

Any suggestions?

Thanks in advance! C.
....
<script type="text/javascript">

function changeText(newtext)
{
text.innerHTML = newtext;
}
</script>

<p id="text">Old text</p>
<input type="button" onclick="changeText(''New text'')" value="Change
text" />
....




我注意到你的代码是XHTML。 innerHTML不适用于XHTML,

并且不应该。


因为Internet Explorer不支持XHTML,并且因为你说你的

页面适用于Internet Explorer,显然你的服务器正在向Internet Explorer说谎
,并说当你的文件是HTML时,它是

真的是XHTML。


但你的服务器仍然可以向Firefox说实话。如果是这样,那么

Firefox非常正确地拒绝做innerHTML。如果这是

的情况,那么你必须将你的页面转换为HTML 4,其中innerHTML

将起作用,或者使用标准DOM方法而不是innerHTML。 />

您可以使用

工具 - >页面信息轻松确定您的服务器告诉Firefox的内容。如果它说页面是XHTML,那那就是你的问题。

-

John W. Kennedy

可悲希望白宫能够将卡利古拉变成一个人物,因为担心最终的力量不可避免地会损害他们的价值。

- James D. Barber(1930-2004)



I notice that your code is XHTML. innerHTML does not work with XHTML,
and isn''t supposed to.

Since Internet Explorer does not support XHTML, and since you say your
page works on Internet Explorer, it is obvious that your server is lying
to Internet Explorer, and saying that your file is HTML when it is
really XHTML.

But your server could still be telling the truth to Firefox. If so, then
Firefox is quite correctly refusing to do innerHTML. If this is the
case, then you must either convert your page to HTML 4, where innerHTML
will work, or use the standard DOM methods instead of innerHTML.

You can easily determine what your server is telling Firefox by using
Tools->Page Info. If it says the page is XHTML, then that''s your problem.
--
John W. Kennedy
"The pathetic hope that the White House will turn a Caligula into a
Marcus Aurelius is as na?ve as the fear that ultimate power inevitably
corrupts."
-- James D. Barber (1930-2004)


这篇关于innerHTML在Firefox中表现不佳?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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