最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

createElement Method

Internet Development Index

Creates an instance of the element for the specified tag.

Syntax

oElement = document.createElement(sTag)

Parameters

sTag Required. String爐hat specifies the name of an element.

Return Value

Returns燼 reference to the new element.

Remarks

In Microsoft® Internet Explorer 4.0, the only new elements you can create are img, area, and option. As of Internet Explorer 5, you can create all elements programmatically, except for frame and iframe. In addition, the properties of these created elements are read/write and can be accessed programmatically. Before you use new objects, you must explicitly add them to their respective collections or to the document. To insert new elements into the current document, use the insertBefore or appendChild methods.

You must perform a second step when using createElement to create the input element. The createElement method generates an input text box, because that is the default input?A HREF="../properties/type_7.html">type property. To insert any other kind of input element, first invoke createElement for input, then set the type property to the appropriate value in the next line of code.

Attributes can be included with the sTag as long as the entire string is valid HTML. You should do this if you wish to include the NAME attribute at run time on objects created with the createElement method.

Attributes should be included with the sTag when form elements are created that are to be reset using the reset method or a BUTTON with a TYPE attribute value of reset.

Examples

This example uses the createElement method to dynamically update the contents of a Web page by adding an element selected from a drop-down list box.

<SCRIPT>
function fnCreate(){
oData.innerHTML="";
var oOption=oSel.options[oSel.selectedIndex];
if(oOption.text.length>0){
var aElement=document.createElement(oOption.text);
eval("aElement." + oOption.value + "='" + oText.value + "'");
if(oOption.text=="A"){
aElement.href="javascript:alert('A link.')";
}
}
oData.appendChild(aElement);
}
</SCRIPT>
<SELECT ID="oSel" onchange="fnCreate()">
<OPTION VALUE="innerText">A
<OPTION VALUE="value">&lt;INPUT TYPE="button"&gt;
</SELECT>
<SELECT ID=oText onchange="fnCreate()">
<OPTION>
<OPTION VALUE="Text">Text
<OPTION VALUE="More and More Text">More and More Text
</SELECT>
<SPAN ID="oData" ></SPAN>
This feature requires Microsoft® Internet Explorer 5 or later. Click the following icon to install the latest version. Then reload this page to view the sample.

You can also specify all the attributes inside the createElement method itself by using an HTML string for the method argument. The following example demonstrates how to dynamically create two radio buttons utilizing this technique.

<HTML>
<HEAD>
<SCRIPT>
function createRadioButton(){
// Create radio button object with value="First Choice" and then insert
// this element into the document hierarchy.
var newRadioButton = document.createElement("<INPUT TYPE='RADIO' NAME='RADIOTEST' VALUE='First Choice'>")
document.body.insertBefore(newRadioButton);
// Create radio button object with value="Second Choice" and then insert
// this element into the document hierarchy.
newRadioButton = document.createElement("<INPUT TYPE='RADIO' NAME='RADIOTEST' VALUE='Second Choice'>")
document.body.insertBefore(newRadioButton);
}
</SCRIPT>
</HEAD>
<BODY>
<INPUT TYPE="BUTTON" ONCLICK="createRadioButton()" VALUE="Create two Radio Buttons"><BR>
<INPUT TYPE="BUTTON" ONCLICK="alert ( document.body.outerHTML )" VALUE="Click here to see HTML">
<BODY>
</HTML>

Standards Information

This method is defined in World Wide Web Consortium (W3C) Document Object Model (DOM) Level 1 Non-Microsoft link.

Applies To

document

See Also

add, cloneNode, removeNode, About the W3C Document Object Model
雅江县| 黄山市| 安国市| 蓝田县| 龙口市| 余姚市| 长沙县| 额尔古纳市| 延津县| 庆城县| 安丘市| 宜宾县| 米泉市| 九龙城区| 土默特左旗| 大邑县| 湟源县| 抚州市| 汝州市| 长武县| 岑溪市| 博湖县| 麻栗坡县| 沽源县| 敦煌市| 宁陵县| 黄龙县| 富顺县| 三门县| 牡丹江市| 深州市| 剑川县| 汕尾市| 青阳县| 朝阳区| 庆城县| 韶关市| 襄垣县| 凤凰县| 汪清县| 桂东县|