gpt4 book ai didi

javascript - 如何将 JavaScript 添加到标记的 HTML 文本中?

转载 作者:行者123 更新时间:2023-11-28 03:27:02 25 4
gpt4 key购买 nike

我正在尝试创建我认为世界上最糟糕的网站。我想使用标签将一些 JavaScript 添加到一些文本中。我自己尝试了一些方法来解决这个问题,但一直没能解决这个问题。我怎样才能让它发挥作用?

(脚本应该使文本变成彩虹色,顺便说一句)该脚本,包括我的文本:

var text= <marquee>"hello and welcoem to my website"</marquee> // YOUR TEXT
var speed=80 // SPEED OF FADE

// ********** LEAVE THE NEXT BIT ALONE!
var el = document.getElementsByTagName('marquee')[0];
if (document.all||document.getElementById){
document.write('<span id="highlight">' + text + '</span>')
var storetext=document.getElementById? document.getElementById("highlight") : document.all.highlight
}
else
document.write(text)
var hex=new Array("00","14","28","3C","50","64","78","8C","A0","B4","C8","DC","F0")
var r=1
var g=1
var b=1
var seq=1
function changetext(){
rainbow="#"+hex[r]+hex[g]+hex[b]
storetext.style.color=rainbow
}
function change(){
if (seq==6){
b--
if (b==0)
seq=1
}
if (seq==5){
r++
if (r==12)
seq=6
}
if (seq==4){
g--
if (g==0)
seq=5
}
if (seq==3){
b++
if (b==12)
seq=4
}
if (seq==2){
r--
if (r==0)
seq=3
}
if (seq==1){
g++
if (g==12)
seq=2
}
changetext()
}
function starteffect(){
if (document.all||document.getElementById)
flash=setInterval("change()",speed)
}
starteffect()
</script>
</b>

最佳答案

试试这个...适用于 https://codepen.io/cunlay/pen/jOOmaRv

<b>
<script>
var text = "<marquee>hello and welcome to my website</marquee>"; // YOUR TEXT
var speed = 80; // SPEED OF FADE
var r = 1, g = 1, b = 1, seq = 1;
var hex = new Array("00","14","28","3C","50","64","78","8C","A0","B4","C8","DC","F0");
var storetext;

// ********** LEAVE THE NEXT BIT ALONE!
var el = document.getElementsByTagName('marquee')[0];
if (document.all || document.getElementById){
document.write('<span id="highlight">' + text + '</span>');
}else{
document.write(text);
}

function changetext(){
var rainbow = "#"+hex[r]+hex[g]+hex[b];
storetext = document.getElementById("highlight");
storetext.style.color = rainbow;
}

function change(){
if(seq==6){
b--;
if(b==0){
seq=1;
}
}else if (seq==5){
r++;
if (r==12){
seq=6;
}
}else if (seq==4){
g--;
if(g==0){
seq=5;
}
}else if (seq==3){
b++;
if (b==12){
seq=4;
}
}else if (seq==2){
r--;
if(r==0){
seq=3;
}
}else if (seq==1){
g++;
if(g==12){
seq=2;
}
}else {
return false;
}
changetext();
}
function starteffect(){
if (document.all || document.getElementById){
var flash = setInterval("change()",speed);
}
return false;
}
starteffect();
</script>
</b>

关于javascript - 如何将 JavaScript 添加到标记的 HTML 文本中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58545854/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com