JavaScript gets sample code for the specified object on the current page

Source: Internet
Author: User
Tags tag name

  This article mainly introduces JavaScript to get the method of the specified object on the current page, the need for friends can refer to the following

How JavaScript gets the specified object on the current page .    method:    code as follows: document.getElementById (ID)//Get object with specified ID value   Document.getelementsbyname (name)//Get an array of objects of the specified Name value   document.all[]//very intelligent stuff but not web standard   document.getElementsByTagName//Get the specified tag value of the object array     below gives an example, just remove the annotation directly run can see the effect .    code as follows: <! DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 transitional//en" >  <HTML>  <HEAD>  <title > New Document </TITLE>  <meta name= "generator" content= "EditPlus" >  <meta name= "Author" Content= "" >  <meta name= "Keywords" content= "" >  <meta name= "Description" content= "" >  </HEAD>    <BODY>  <form method= "POST" name= "mainfrm" action= "" >  <input Type = "hidden" name= "text" id= "text" style= "width:100%" value= "Practice only" >  <input type= "hidden" name= " OrganizationId "style=" width:100% "value=" validation document.all ">  <table width=" 100% "border=" 1 "> ; TR height= >  <td width= "15%" align= "right" > Inventory Organization:</td>  <td width= "20%" ><input Type= "text" name= "OrganizationId" id= "OrganizationId" style= "width:100%" value= "inventory organization" ></td>  </TR >  <tr>  <td width= "15%" align= "right" > sub-Library code:</td>  <TD width= "20%" >  <select name= "Subinventorycode" style= "width:100%" id= "Subinventorycode" >  <option value= "QTWL" > qtwl</option>  <option value= "BTSPT" >BTSPT</option>  <option value= "BTS" >BTS< /option>  </select>  </td>  </tr>  height= "<tr" >  <td Colspan= "2" align= "center" ><input type= "button" value= "Get specified object" onclick= "Do_check ()" ></td>  < /tr>  </table>  </form>  </BODY>  </HTML>  <script language= " JavaScript ">  <!--  function Do_check () { //getElementById: That'sAn element is obtained by ID, so only the element with the ID set is accessible. The return value of the  /method ensures that you need the object, because the ID value of an object in the entire page is unique.  //var OrganizationId = document.getElementById ("OrganizationId"); //alert (Organizationid.value);     //Getelementsbyname: The element is obtained by name. The return value of the  /method is an array, and it is returned as an array even if there is only one object in the entire page whose Name property is the given value.  //Only the length of the array is one.  //var OrganizationId = Document.getelementsbyname ("OrganizationId"); //alert (Organizationid[0].value);  /alert (organizationid.length);   //getElementsByTagName: Get elements by tagname (tag name) A document will of course have the same label, //So this method and Getelementsbyname basic acquaintance is also to get an array, just to get the difference in the way of the object.  //var inputs = document.getElementsByTagName ("input"); //alert (Inputs.length); //Alert (inputs[0). Value); //alert (Inputs[1].value); //alert (Inputs[2].value);   //document.all[] is an array variable consisting of all the tags in the document, including all elements in the Document object.  //Generally get the specified element by name, but it's smarter than getelementsbyname. If one of the eligible objects returns this object, multiple returns the  //var organizationid in the form of an array = Document.all["OrganizationId"]; /alert (organizationid[0].value)  //document.all["OrganizationId"] // Document.All.Item ("OrganizationId")  } //-->  </SCRIPT>   
Related Article

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.