JavaScript function arguments are _javascript techniques that can have defaults

Source: Internet
Author: User
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd "> <ptml xmlns=" http://www.w3.org/1999/xhtml "> <pead> <meta http-equiv=" Content-type "content=" text/html; charset=gb2312 "/> <title> Untitled document </title> <script type=" Text/javascript ">/** * Get element * Parameter description according to class name: * 1, ClassName class name * 2, Tag element name default all elements * 3, Elm parent element default Doucment/Document.getelementsbyclassname = function (ClassName, TA G, Elm) {var testclass = new RegExp ("(^|\s)" + ClassName + "(\s|$)"); var tag = Tag | | "*"; var elm = Elm | | Document var elements = (Tag = = "*" && elm.all)? Elm.all:elm.getElementsByTagName (tag); var returnelements = []; var current; var length = Elements.length; For (Var i=0. i<length; i++) {current = Elements[i]; if (Testclass.test (Current.classname)) {Returnelements.push (current); } return returnelements; } window.onload = function () {var divs = Document.getelementSbyclassname ("div"); alert (divs.length); for (var i = 0; i < divs.length i++) {alert (divs[i].id); } </script> </pead> <body> <div class= "div" id= "div1" > </div> <div class= "DIVVVV "Id=" Div2 "> <div class=" div "id=" div21 "> </div> </div> <div class=" div "id=" div3 "> </d Iv> </body> </ptml>
[Ctrl + A All SELECT Note: If the need to introduce external JS need to refresh to perform]

Here I quote this code not because it is convenient for me to call later, but to find a point I never use the method.

Getelementsbyclassname has three parameters, but the call does not have to pass three parameters, you can only pass the first argument, the other two parameters have a default value.

The original JavaScript function parameters can be the default, which I have never known.

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.