Home > front end >  The font change color, what's wrong? Why don't change color
The font change color, what's wrong? Why don't change color

Time:10-05

Asks the user in the color selection drop-down text box, through the onchange time accordingly change the font color text box,
& lt; html>
& lt; head>
& lt; Script language="javascript" & gt;
The function Fcolor () {
Var e=window. The event;
Var obj=e.s rvElement;
Form1. Textfield. Style. Color=obj. Option [obj. SelectedIndex] value;
}
& lt;/script>
& lt;/head>
& lt; body>
& lt; The form name="form1" method="post" action="" & gt;
& lt; Input name="txtfiled" type="text" value="https://bbs.csdn.net/topics/JavaScript" video lectures & gt;
& lt; Select the name="menu1" onChange="Fcolor ()" & gt;
& lt; The option value="https://bbs.csdn.net/topics/black" & gt; Black & lt;/option>
& lt; The option value="https://bbs.csdn.net/topics/yellow" & gt; Yellow & lt;/option>
& lt; The option value="https://bbs.csdn.net/topics/blue" & gt; Blue & lt;/option>
& lt; The option value="https://bbs.csdn.net/topics/green" & gt; Green & lt;/option>
& lt; The option value="https://bbs.csdn.net/topics/red" & gt; Red & lt;/option>
& lt; The option value="https://bbs.csdn.net/topics/purple" & gt; The purple & lt;/option>
& lt;/select>
& lt;/form>
& lt;/body>
& lt;/html>

CodePudding user response:

Can change just strange!
Where the above function of e, form1 again which come of, direct error, and the following onchange note case (no caps),
 
The function Fcolor (e) {
The console. The log (e)
The console. The log (e.v alue)
Const color=e.v alue.
Form document. QuerySelector (" input "). Style. Color=color;;
}
//,,,
& lt; Select the name="menu1" onchange="Fcolor (this)" & gt;

CodePudding user response:

The function Fcolor () {
Var e=window. The event;
var obj=e.s rvElement; e.s rcElement;
form1. Textfield. Style. Color=obj. Option [obj. SelectedIndex] value; form1. Txtfield. Style. Color=obj. Options [obj. SelectedIndex] value;
}

CodePudding user response:

You can press F12 debugging and see yourself, you have the wrong number of several words,

CodePudding user response:

 
& lt; html>
& lt; head>
& lt; Script language="javascript" & gt;
The function Fcolor () {
Form1. Txtfiled. Style. Color=form1. Menu1. Value;
}
& lt;/script>
& lt;/head>
& lt; body>
& lt; The form name="form1" method="post" action="" & gt;
& lt; Input name="txtfiled" type="text" value="https://bbs.csdn.net/topics/JavaScript" video lectures & gt;
& lt; Select the name="menu1" onchange="Fcolor ()" & gt;
& lt; The option value="https://bbs.csdn.net/topics/black" & gt; Black & lt;/option>
& lt; The option value="https://bbs.csdn.net/topics/yellow" & gt; Yellow & lt;/option>
& lt; The option value="https://bbs.csdn.net/topics/blue" & gt; Blue & lt;/option>
& lt; The option value="https://bbs.csdn.net/topics/green" & gt; Green & lt;/option>
& lt; The option value="https://bbs.csdn.net/topics/red" & gt; Red & lt;/option>
& lt; The option value="https://bbs.csdn.net/topics/purple" & gt; The purple & lt;/option>
& lt;/select>
& lt;/form>
& lt;/body>
& lt;/html>

CodePudding user response:

It isn't get from1, don't get how to change
  • Related