Home > Web Front-end > JS Tutorial > Summarize AJAX related JS code snippets and browser models_javascript skills

Summarize AJAX related JS code snippets and browser models_javascript skills

WBOY
Release: 2016-05-16 19:09:59
Original
858 people have browsed it

In .net development, it is a good thing to make full use of free controls, but if you cannot modify the controls to meet your own needs, you must use JS. The premise is to study the method attributes of various objects in the browser model. Especially if you are familiar with CSS and HTML, you will be able to do it very cool. As far as the JS language itself is concerned, the requirements are not high.

1. Tips for dynamically deleting the contents of Table. No need to write too much code. One line:

tb.removeNode(true)

2. Dynamically add rows, except CreateElement The method can also be shorter like this:

<table id=tb1></table>
<SCRIPT>
function addTable(){
var row1 = tb1.insertRow();
var cell1=row1.insertCell();
var cell2=row1.insertCell();
cell1.innerText="Baby Gray Bean";
cell2.innerText="Super Big Stupid Wolf"
}
</SCRIPT>
<INPUT TYPE = "button" VALUE = "AddTable" onclick = "addTable()">

 3. Dynamically add Table 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. To delete Table in DIV, simply Div.innerHTML="".
The above are some practical and relatively short codes. Of course, there are various other ways to achieve it, but they are generally longer than the above, such as combining the insertAdjacentHTML method of the DIV object, etc. Different methods are used under different needs. The premise is to study well Method attributes of various objects of the browser model. Especially if you are familiar with CSS and HTML, you will be able to do it very cool. As far as the JS language itself is concerned, the requirements are not high.

The following is an example of the Document object. The relevant methods are:

Method Description
attachEvent
createAttribute
createComment
createDocumentFragment
createElement
createEventObject
createStyleSheet
createTextNode
detachEvent
getElementById
getElementsByName
getElementsByTagName
mergeAttributes
recalc
write
writeln
Take the DIV object as Examples of related methods include:

addBehavior
appendChild
applyElement
attachEvent
clearAttributes
cloneNode
contains
detachEvent
getAdjacentText
getAttribute
getAttributeNode
getElementsByTagName
hasChildNodes
insertAdjacentElement
insertAdjacentHTML
insertAdjacentText
insertBefore
mergeAttributes
normalize
removeAttribute
removeAttributeNode
removeBehavior
removeChild
removeexpression

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template