Home > front end >  HTML text color for click text color refresh also retention
HTML text color for click text color refresh also retention

Time:09-17



The initial opening can be such a

Click on the button below to 1, I am 1 becomes green, click again on the black

Click on the button below to me is 2 becomes green, click again also become black

Keep after click on the color is the main, I after refresh or click on the color, to open and click on the color, keep click on a color,

Great god help solve, genuflect is begged as simple as possible,

CodePudding user response:

 








<style>
Green {
Background: green;
color: #fff;
}
The black {
Background: black;
color: #fff;
}
</style>
<script>
The function change (el) {
Var cl=el className,
Id=el. Id
The console. The log (cl)
if (! Cl) {
Cl='green'
} else if (cl==='green') {
Cl='black'
}
El. The className=cl
LocalStorage [id]=cl
Document. GetElementById (id + 'x'). The innerHTML='I am' + id
LocalStorage [id + 'x']='I am' + id
}

Window. The onl oad=function () {
For (let k in localStorage) {
If (k.i ndexOf (' BTN) & gt; 1 & amp; & K.i ndexOf (' x ')==1) {
If (localStorage [k]) {
Document. The getElementById (k). The className=localStorage [k]
}
}
If (k.i ndexOf (' x ') & gt; 1 & amp; & K.i ndexOf (' BTN) & gt; 1) {
If (localStorage [k]) {
Document. The getElementById (k). InnerHTML=localStorage [k]
}
}
}
}
</script>

CodePudding user response:


To such a simple line, main is once again open to retain my close color , best can use TXT or other

CodePudding user response:

 








<style>
Green {
Color: green;
}
</style>
<script>
The function change (index) {
Var el=document. GetElementById (" text "+ index),
Cl=el. The className
if (! Cl) {
Cl='green'
} else if (cl==='green') {
Cl='
}
El. The className=cl
LocalStorage [' text '+ index]=cl
}

Window. The onl oad=function () {
For (let k in localStorage) {
If (k.i ndexOf (' text ') & gt; 1) {
Document. The getElementById (k). The className=localStorage [k]
}
}
}
</script>

CodePudding user response:

Local storage, next time you come in first with the local configuration

CodePudding user response:

Put a label to make button, use a: visited pseudo class should be able to implement
  • Related