Home > front end >  This how to write
This how to write

Time:11-04

CodePudding user response:



<meta charset="utf-8"/& gt;
Arguments

<body>

I am a paragraph!


<script type="text/javascript">
//add code here
The function of CSS () {
The arguments [0]=elem;
The arguments [1]=valueName;
The arguments [2]=value;
If (the arguments. Length==2) {
The return value.
} else if (the arguments. Length==3) {

}

}
</script>


CodePudding user response:

 

<script>
The function of CSS (element, propName, propVal) {
If (propVal!==! 1 & amp; & ! PropVal) {
The return element. Style [propName]//the return value
} else {
Element. Style [propName]=propVal. ToString ()//set the style
}
}
Const element=document. GetElementById (" test ");
Const backgroundColor=CSS (element, "backgroundColor");
The console. The log (backgroundColor);//=& gt; Black
CSS (element, "backgroundColor", "blue");
The console. The log (element. Style. BackgroundColor);//=& gt; 'blue'
</script>

CodePudding user response:

 
<body>

I am a paragraph!


<script type="text/javascript">
//add code here
The function of CSS () {
Var elem=the arguments [0].
Var attr=the arguments [1].
Var value=https://bbs.csdn.net/topics/arguments [2];
If (the arguments. Length==2) {
Return elem. Style [attr] | | 'black'.
} else if (the arguments. Length==3) {
Elem. Style [attr]=value
}

}
The parameter//3
CSS (document. GetElementById () 'test', 'background - color', 'orange')
//two parameters obtained by default color black
Var v=CSS (document. GetElementById () 'test', 'color')
The console. The log (v)
</script>

  • Related