Use JavaScript to perform the following operations on a <div>: Document. getelementbyid ("divtest"). width = 50;
<Div id = "divtest" width = "100" type = "option" text = "option"> </div>
How can I get the original width of divtest ??
I remember that the Web workshop used a table to record the similarities and differences between the "current value" and "Initial Value ".
<HTML>
<Head>
<Title> </title>
<Script language = "JavaScript">
<! --
Function changevalue ()
{
Divtest. runtimestyle. width = "200 ";
Txttest. value = "";
}
Function getoriginal ()
{
VaR STR = "the current value of txttest is:" + txttest. Value + "\ n ";
STR + = "the initial value of txttest is:" + txttest. defaultvalue + "\ n ";
STR + = "the current width of divtest is:" + divtest. currentstyle. Width + "\ n ";
STR + = "The initial width of divtest is:" + divtest. style. Width
Alert (STR );
}
// -->
</SCRIPT>
</Head>
<Body>
<Input id = "button1" type = "button" value = "change attribute" name = "button1" onclick = "changevalue () "> <input id =" button2 "type =" button "value =" Get Original attributes "name =" button2 "onclick =" getoriginal () ">
<Br/>
<Input id = "txttest" type = "text" name = "txttest" value = "text test">
<Div style = "border-Right: Blue 2px solid; border-top: Blue 2px solid; border-left: Blue 2px solid; width: 80px; border-bottom: blue 2px solid"
Id = "divtest"> test Div </div>
</Body>
</Html>