After opening a homepage today, an animation is displayed in the header. It was easy to add the expanded code. It can be found that the header file of the original program is stored in head.html and then included. In this example, we need to put a div for expansion in head.html. However, all the pages have the expansion effect, but I only need to have this effect on the homepage. There are two solutions:
1. Set the display of the div in the header to none, and call js to set it to block.
2. Use js to dynamically create a div and place the div at the beginning. This adds a few more words, as shown below:
<Script language = "javascript" type = "text/javascript"> var divObj = document. createElement ("div"); divObj. innerHTML = "hi, welcome to www.phpernote.com php programmer tutorial network! "; Var first = document. body. firstChild; // get the first element document. body. insertBefore (divObj, first); // Insert before the first element </script>
Next we will share with you how to dynamically create html elements (using createElement) in FireFox)
Let's take a look at the following code (this code is problematic ):
<script type="text/javascript">function add(){var input=document.createElement("<input size=30 type=\"text\" name=\"extrachildren[]\">")var br=document.createElement("<br>");var br2=document.createElement("<br>");document.getElementById("children").insertBefore(br);document.getElementById("children").insertBefore(br2);document.getElementById("children").insertBefore(input);</script>
The above code is feasible in IE, but it does not work in FireFox. To play a role in FireFox, you must replace it with the following code:
<script type="text/javascript">function add(){ var input=document.createElement('input'); input.setAttribute('size','30'); input.setAttribute('type','text'); input.setAttribute('name','extrachildren[]'); var parent=document.getElementById('children'); parent.insertBefore(document.createElement('br'),null); parent.insertBefore(document.createElement('br'),null); parent.insertBefore(input,null);}</script>
You can create an element in either of the following ways:
Document. createElement ("<input type = text> ")
Document. createElement ("<input> ")
Document. createElement ("input ")
Firefox only supports one method:
Document. createElement ("input ");
Document. setAttribute (name, value );
Articles you may be interested in
- Insert element in js to the front of the page body
- Jquery obtains the index number of the current element in the Peer element.
- Note the following when querying strings with single quotes and inserting strings with single quotes in Mysql:
- How does php Delete the first and last elements of an array?
- A classic dialogue between programmers and testers. These are shared by foreign programmers, who say they are used globally?
- Code used to test the password strength of a user input using Javascript
- Js restrictions: Only English letters and numbers can be entered. Chinese characters and other special characters cannot be entered.
- JQuery determines whether an element exists