Home > front end >  Variables in the value of input element failure
Variables in the value of input element failure

Time:04-27

The source code
 & lt; ! DOCTYPE html> 


<meta charset="utf-8" & gt;


<body>



<script>
Var test=document. GetElementById (" input "). The value;
The function start () {
Alert (test).
}
</script>

The input in the input box, and then click "pop-up", the content of the popup nothing
When the
 alert (test); 
the test is changed to
 document. The getElementById (" input "). The value; 

Then input box input, click the pop-up, the content of the popup to the content of the input

CodePudding user response:

To get the value of the information on the function, otherwise the test done in page load has been get the value, the page is loaded complete you haven't input so no value
Var test=document. GetElementById (" input "). The value; Inside the function alert (test); Before is ok

CodePudding user response:

Variable declarations and not to the assignment after assignment must or previous value, you this statement assignment or empty,

Var test=document. GetElementById (" input ")

Alert (test. The value)

So, to get the value through the dom

CodePudding user response:

So to achieve:

 



<meta charset="utf-8" & gt;


<body>



<script>
Var test;
The function start () {
Test=document. GetElementById (" input ");
Alert (test. The value);
}
</script>


  • Related