Summarizing AJAX-related JS code snippets and browser models

Source: Internet
Author: User

In. NET development, it is good to make full use of free controls, but if you cannot modify the control to reach your own needs, you will need to use the JS method, the premise is to study the various objects of the browser model of the method attribute. Especially familiar with the css+html will do very cool. As for the JS language itself, the requirements are not high.

1, dynamic Delete table inside the content skill, do not need to write too many code, a line:

tb.removeNode(true)

2, dynamic increase line, in addition to the CreateElement method, but also this relatively short:

<table id=tb1></table>
<SCRIPT>
function addTable(){
 var row1 = tb1.insertRow();
 var cell1=row1.insertCell();
 var cell2=row1.insertCell();
 cell1.innerText="灰豆宝宝";
 cell2.innerText="超级大笨狼"
}
</SCRIPT>
<INPUT TYPE = "button" VALUE = "AddTable" onclick = "addTable()">

3. Add table dynamically in Div

<SCRIPT>
function addTable(){
 var tb1 = document.createElement("table";
 tb1.border="1px";
 var row1 = tb1.insertRow();
 var cell1=row1.insertCell();
 var cell2=row1.insertCell();
 mydiv.appendChild(tb1);
 cell1.innerText="wanghr100";
 cell2.innerText="panyuguang962"
}
</SCRIPT>
<BODY>
<div id=mydiv style="width:400;height:300;"></div>
<INPUT TYPE = "button" VALUE = "AddTable" onclick = "addTable()">

4, in the div delete table, simple as long as div.innerhtml= "" can.

The above is a few practical relatively short code, of course, there are other ways to achieve, but generally more than the length of the above, such as the combination of the use of Div object insertAdjacentHTML method, in different needs under different methods, the premise is to study the browser model of the various objects of the method attribute. Especially familiar with the css+html will do very cool. As for the JS language itself, the requirements are not high.

The following are examples of document objects:

Method Description

Attachevent

CreateAttribute

Createcomment

Createdocumentfragment

CreateElement

Createeventobject

createStyleSheet

createTextNode

DetachEvent

getElementById

Getelementsbyname

getElementsByTagName

Mergeattributes

Recalc

Write

Writeln

Take a Div object as an example related methods are:

Addbehavior

AppendChild

Applyelement

Attachevent

Clearattributes

CloneNode

Contains

DetachEvent

Getadjacenttext

GetAttribute

GetAttributeNode

getElementsByTagName

HasChildNodes

Insertadjacentelement

insertAdjacentHTML

insertAdjacentText

InsertBefore

Mergeattributes

Normalize

RemoveAttribute

Removeattributenode

Removebehavior

RemoveChild

Removeexpression

Removenode

Replaceadjacenttext

ReplaceChild

ReplaceNode

SetActive

SetAttribute

Setattributenode

SetExpression

Other, such as Drop-down list objects, and drag-and-drop operations and so I have time to collate and compare, to achieve the same function, relatively short of the wonderful code is worth collecting.

1. Removenode (true) not supported by IE browser, should be used Obj.parentNode.removeChild (obj);

2. InsertRow (x) InsertCell (y) This parameter is the default in IE, but not the default in non IE browsers

As for Insertadjacentelement innertext These are the specific methods of IE, rather than the standard of the consortium, it should be noted.

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.