Javascript 更改跨度文本?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8177215/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-24 04:59:01  来源:igfitidea点击:

Change span text?

javascripttextedithtml

提问by user1053018

Possible Duplicate:
How do I change the text of a span element in javascript

可能的重复:
如何在 javascript 中更改 span 元素的文本

Well, I've searched a lot for the answer to this, but still I couldn't find it. What I did find didn't work.

嗯,我已经搜索了很多答案,但仍然找不到。我发现的没有用。

What I'm trying to do is, basically, using JavaScript: At the browser's bar, not via Greasemonkey or something else, edit a span's text .

我想要做的是,基本上,使用 JavaScript:在浏览器的栏中,而不是通过 Greasemonkey 或其他东西,编辑 span 的 text 。

This' the span that contains the text I want to edit:

这是包含我要编辑的文本的跨度:

<span id="serverTime">5:46:40</span>

The time within is just random, don't pay attention to it, it's what I want to edit using javascript..

里面的时间只是随机的,不要在意,这是我想用javascript编辑的..

I'm a newbie so yeah :\

我是新手所以是的:\

回答by SLaks

document.getElementById("serverTime").innerHTML = ...;

回答by Purag

Replace whatever is in the address bar with this:

用这个替换地址栏中的任何内容:

javascript:document.getElementById('serverTime').innerHTML='[text here]';

Example.

例子