JavaScript practical application: innerHTMl and confirmed the use of tips

Related Tags:

  Today involved in the development of a layer of information control is the control of a Display of what information, find that the use of information in order to control innerHTML attribute of the value of this form inside with the innerHTML attribute a value similar to the control layer Showing value. 

  For example, a div layers, I had no value, I am a punishment after the incident to show that value, then they can use innerHTML attribute, but in fact innerHTML attribute addition to control layer, can control all the elements of window content, but I did not test too. 

  (1) control of the div tags 

  Div tags with the label is not the same span, div is a layer of the block, is his span, we see the following demonstration will know the difference.    Div control of the first section of the code. 

  <script Language="javascript"> 
  Function chageDiv (number) 
  ( 
  If (number == 1) ( 
  Document.getElementById ( "div1"). InnerHTML = "value of 1"; 
  ) 
  If (number == 2) ( 
  Document.getElementById ( "div1"). InnerHTML = "value of 2"; 
  ) 
  ) 
  </ Script> 

  DIV block test: <div id = "div1"> default value </ div> 

  <a Href="#" onClick="chageDiv(1)"> for a change of </ a> 
  <a Href="#" onClick="chageDiv(2)"> change in value of 2 </ a> 

  Running, click on "value for a change," then the "default" contents will be changed to "value of 1," but attention to the interface that will be found "DIV test:" and the "default" is 2 to show that, because DIV is based on the block to show. 

  (2) the span of control 

  And div similar, but it is in accordance with the trip to show that, look at the code below: 

  Function chageSpan (number) 
  ( 
  If (number == 1) ( 
  Document.getElementById ( "span1"). InnerHTML = "value of 1"; 
  ) 
  If (number == 2) ( 
  Document.getElementById ( "span1"). InnerHTML = "value of 2"; 
  ) 
  ) 
  </ Script> 
  Span to test: 
  <span Id="span1"> default value </ span> <br> 
  <a Href="#" onClick="chageSpan(1)"> for a change of </ a> 
  <a Href="#" onClick="chageSpan(2)"> change in value of 2 </ a> 

  When click the "value for a change", "default" will turn into "a value", but "to test Span" and the "default" is shown on the same line with the DIV not the same. 

  Another noteworthy is, or whether div span, as the name id to the definition of that is not the same as the form is used to define the name. 

  (3) confirm the production confirmed boxes 

  When we need to implement a dangerous operation, such as the deletion of a certain content, and so on, then they should be given the corresponding user prompts users is not easy to make mistakes.    Tips are generally used confirm () function to deal with, and submit to it as a parameter display information tips, visit the pop-up dialog box will be the time, if clicking on the "OK" then will be diverted to function returns true, click on the " Cancellation "will be released false, we focused on the characteristics of the two methods used to control user whether to implement an action. 

  Look at the code: 

  <script Language="javascript"> 
  Function accessNeteasy () 
  ( 
  If (confirm ( 'Do you really want to visit Netease news?')) ( 
  Location = 'http://calendar.eyou.eyou'; 
  ) 
  ) 
  Function accessSina () 
  ( 
  If (confirm ( 'Are you sure visit Sina news?')) ( 
  Return true; 
  Else () 
  Return false; 
  ) 
  ) 
  </ Script> 

  Visit one way: 
  <a Href="#" onClick="accessNeteasy()"> I love DivCSS </ a> <br> 
  Two visits: 
  <a Href=" http://www.webjx.com "I love DivCSS onClick="return accessSina()"> </ a> 

  We built two functions, one accessNeteay, a accessSina, Sina and Netease visit, we use different methods, the first point is that when the link, the judge If it is true, then on the link to the designated location, Comparison of methods is not universal, only on individual links.    The second method is to use the return value in the form of the visit to determine when to return to true, and uncertain time returns false, then this can be done against any links, the information written in a generic tips, convenient page call . 

  Above code are tested through, can themselves on the basis of this expansion, the need to write their own JavaScript code. 

Related articles:

CSS of the need to
  Elements    From the classification, the two kinds of elements    1. Replacement can be: no text    2. By the non-replacement: a content    From the performance, the two kinds of elements    1. Block-level elements:    2. Trip...
Beginners Guide to HTML - tags, attributes and elements
  HTML is a simple text markup language, but she also with a number of other different text files such as doc, wps, and we should learn more points related to the content to make it an effective HTML file.    Tags    An HTML document, including the basic structure of labe...
Improve code performance on skills - to create 1,000 firms form as an example
  Microsoft's development cycle is a very important adjustment of product performance.    Property developers should be adjusted is a key part of the carefully.    Through years of development, the industry on how to optimize the performance Win32 has been a lot of unde...
Website Promotion Act Fast
  The purpose of the promotion is to improve the site the site was visited by a network and marketing objectives.    Based on this premise, the website operators should take advantage of the Internet for their own identity and target market positioning accuracy, and allow more potent...
Famous animation division on the recommendations of the blink of an eye
  Mike Caputo:    Need to focus on is that the reality of life in the blink of an eye and the way actors, animators used is not the same.    Ed Hooks chipped in to here, but in real life we blink because we need.    Performers blink of an eye is to achieve drama ...