简体   繁体   English

选取框的nodeValue动态更新

[英]Marquee nodeValue update dynamically

I have a basic problem where I couldn't update the marquee nodeValue dynamically. 我有一个基本问题,无法动态更新选取框的nodeValue。 The following is the HTML Code. 以下是HTML代码。

<!DOCTYPE html>
<html>
    <head>
       <script src="update.js" language="javascript" type="text/javascript"></script>
    </head>
    <body>
       <marquee behavior="scroll" direction="left" id="marquee"></marquee>
    </body>
</html>

And the update.js is 而update.js是

document.getElementById("marquee").firstChild.nodeValue = "New Text";
document.getElementById("marquee").start();

Can anyone tell me how to update the Marquee from other javascript. 谁能告诉我如何从其他JavaScript更新字幕。

Your marquee element does not have a firstChild . 您的marquee元素没有firstChild Your code will work as it is if you give it a default value: 如果您给它一个默认值,您的代码将按原样运行:

<marquee behavior="scroll" direction="left" id="marquee">Default</marquee>

Alternatively, you can set its textContent (or innerText where appropriate): 另外,您可以设置其textContent (或在适当时设置innerText ):

document.getElementById("marquee").textContent = "New Text";

But marquee ... really?! 但是marquee ...真的吗? I'd suggest looking at alternative solutions. 我建议寻找替代解决方案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM