In Baidu Ife brush problem is own a mistake caused me to <input type= "text"/> Learning.
Paste the code First:
<! DOCTYPE html> for= "Weather_input" > Please enter Beijing today air quality: <input id= "Weather_input" type= "text"/></label> <button id= "confirm _button "> Confirmation </button> <p> The value you entered is: <span id=" Value_show "> Not yet entered </span></p><script Type= "Text/javascript" >window.onload=function(){ varButton=document.getelementbyid ("Confirm_button"); varSpan=document.getelementbyid ("Value_show"); varInput=document.getelementbyid ("Weather_input"). Value; Button.onclick=function() {span.innerhtml=input;}}</script></body>
This code is syntactically correct, but logically problematic: Var Input=document.getelementbyid ("Weather_input"). value; Input in this statement gets the default value of input box. When the Button.onclick is triggered, the value of input cannot be updated immediately, and the program will not be able to display the immediate effect.
This leads to the question that is discussed today: what is the default value of value when the initial value of value is not specified in the <input type= "text"/> and the user is not entered?
null or undefined or ""?
from Var Input=document.getelementbyid ("Weather_input"). Value See, we can see document.getElementById ("Weather_input") This element node object is present, is not empty, and therefore excludes null.
As to whether it is "" or undefined, I have found the answer through practice.
<! DOCTYPE html> for= "Weather_input" > Please enter Beijing today air quality: <input id= "Weather_input" type= "text"/></label> <button id= "confirm _button "> Confirmation </button> <p> The value you entered is: <span id=" Value_show "> Not yet entered </span></p><script Type= "Text/javascript" >window.onload=function(){ varButton=document.getelementbyid ("Confirm_button"); varSpan=document.getelementbyid ("Value_show"); Alert (document.getElementById ("Weather_input"). value===undefined);//Verify that it is equal to undefinedAlert (document.getElementById ("Weather_input"). value=== "");//Verify that equals ""}}</script></body>
From the above code, I see the program run the result is: The first pop-up box is displayed as false, the second pop-up box is displayed as true.
The conclusion is obvious: the default value of value is "" when the initial value of value is not specified in the <input type= "text"/> and the user is not entered at the same time.
<input type= "text"/> The default value of the property when not entered--js learning path