JavaScript dynamically creates an input text box

Source: Internet
Author: User

<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 "/>
<title> JavaScript dynamically create input text box </title>
<style type= "Text/css" >
<!--
Body {
font:12px "Microsoft Sans Serif";
}
. textstyle{
width:300px;
height:16px;
line-height:16px;
border:1px solid #006699;
font:12px "Microsoft Sans Serif";
padding:2px;
Color: #006699;
}
-->
</style>
<script type= "Text/javascript" >
Copyright 2008
By Xiao Wu classmate qq:100052800
Date 2008-11-25

Create an input text box
function Createinput () {
var input = document.createelement ("input");
Input.type = "text";
Input.id = "Inputtext";
Input.value = "This text box is JS created";
If you use CSS to define the input style, you can use ClassName to specify the style name, such as using JS to create, and let go of the comments below
Input.classname = "TextStyle";
Use the following definitions to annotate//input.classname = "TextStyle";
/*input.style.width = "300px";
Input.style.height = "16px";
Input.style.lineHeight = "16px";
Input.style.border = "1px solid #006699";
Input.style.font = "12px ' Microsoft Sans Serif '";
input.style.padding = "2px";
Input.style.color = "#006699";
document.getElementById ("Showtext"). appendchild (input);
}
</script>


<body onload= "Createinput ()" >
<div id= "Showtext" ></div>
<input type= button "onclick=" Alert (document.getElementById (' Inputtext '). Value) "value=" gets the value to create the text box/>
</body>

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.