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.
- Making use of JavaScript and CSS floating menu
- JavaScript dynamic CSS, rejuvenate technology
- Absolute classic pulley news show (javascript + css)
- If I really like HTML, CSS and JavaScript again?
- CSS + JavaScript create cool Menu
- Calling in the CSS JAVASCRIPT
- In the CSS style exterior use JavaScript
- CSS + javascript dialog box of colors
- [Javascript] [CSS] runtimeStyle and style, cssText
- JavaScript build with the CSS + page tab
- Javascript - css Cascading Style Sheets
- Several good php, css, the javascript IDE.
- Javascript and CSS will be written into a document
- Javascript + css achieve tab function
- Call css javascript
- Web layout display. Index posted CSS + javascript
- By Xslt / CSS / Xml / Javascript labeling
- HTML, JavaScript, css reference case
- Javascript entry (for CSS / JS / XSS beginners reference)
- Css + javascript drop-down menu




