Common JS methods (DOM operations)

Source: Internet
Author: User

 

<Select name = "select" size = "1" class = "lianjie" onChange = "window. open (this. options [this. selectedIndex]. value, '_ blank') "style =" background: # fd8a29 ">
<Option value = ""> Jiangxi Provincial university ideological and political network link </option>
<Option value = "http://www.jxmu.edu.cn"> shengde net, School of Medicine, Nanchang University </option>
<Option value = "http://www.qzjci.com"> Jingdezhen Emy of ceramics Truth Network </option>
<Option value = "http://www.md.jxufe.cn/"> Mingde network, Jiangxi University of Finance and Economics </option>
<Option value = "http://www.ecjtu.net/"> sun xinnet of East China Jiaotong University </option>
<Option value = "http://qh.nchu.jx.cn/"> Nanchang Institute of Aeronautics and Astronautics </option>
</Select>

========================================================== ========================================================== ==========

JS timed refresh page:

<Script language = "javascript">
Function myrefresh ()
{
Window. location. href = "login. aspx ";
}
SetTimeout (myrefresh, 2000); // refresh once in 2 seconds
</Script>

========================================================== ========================================================== ==========
Function: Split ()
Function: uses a specified separator to split a string and store it in an array.
Example:

 

Str = "jpg | bmp | gif | ico | png ";
Arr = theString. split ("| ");
// Arr is an array containing character values "jpg", "bmp", "gif", "ico", and "png"

Function: Join ()
Function: combines an array into a string using the separator you selected.
Example:

Var delimitedString = myArray. join (delimiter );
Var myList = new Array ("jpg", "bmp", "gif", "ico", "png ");
Var portableList = myList. join ("| ");
// The result is jpg | bmp | gif | ico | png.

Function: substring ()
Function: String truncation. For example, substring () is used to obtain "minidx" from "minidxsearchengine)

 

Function: indexof ()
Function: returns the subscript of the first character matching the substring in a string.

Var myString = "JavaScript ";
Var w = myString. indexOf ("v"); w will be 2
Var x = myString. indexOf ("S"); x will be 4
Var y = myString. indexOf ("Script"); y will also be 4
Var z = myString. indexOf ("key"); z will be-1

========================================================== ========================================================== ==========

OBJ. Innerhtml,OBJ. Outerhtml

If <Div id = "Container"> <a herf = http://www.baidu.com> Baidu </a> </div>

----> Var OBJ = Get. elementbyid ("Container ")
OBJ. innerhtml is equal to <a herf = http://www.baidu.com> Baidu </a>

You can delete yourself when obj. outerhtml = "" is set in Js. In other words, you can delete an object node by setting the object's outerhtml attribute value.

========================================================== ========================================================== ==========

JS object change event:
Eg.

<Script type = "text/ecmascript" language = "javascript">
Function fn1 ()
{
Alert ("events before change! ");
}
Function fn2 ()
{
Alert ("changed events! ");
}
Function changClick ()
{
Var iptChk = document. getElementById ("iptChk ");
IptChk. onclick = fn2;
}
</SCRIPT>

<Div> <input type = "checkbox" id = "iptchk" value = "123456" onclick = "fn1 ();"/> </div>

<Br/>
<A onclick = "changclick ();" style = "cursor: pointer;"> change event </a>

========================================================== ========================================================== ==========
// Recommend the website address to a friend

Function copytoclipboard ()
{
VaR clipboardcontent = '';
Clipboardcontent + = Document. title;
Clipboardcontent + = Window. Location. href;
Window. clipboardData. setdata ("text", clipboardcontent );
Alert ("You have copied the link and the title. You can paste it to QQ, Popo, MSN, and so on to share it with your friends! ");
}

 

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.