[Post] How to Use js to find the original set value of Div or textbox?

Source: Internet
Author: User

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>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.