Methods for outputting information in javascript-confirmation box-Prompt input box-Document Stream output, javascript input box
How to output information in js
1. Document Stream output
Document. write ('hello ');
2. modal dialog box for the output information prompt box
Window. alert ('content to be displayed output'); or alert ('content to be displayed output ');
Alert (n );
3. Information confirmation box
Var f = window. confirm ('Do you want to enter xinlang net'); confirm ("");
If (f ){
Location. href = 'HTTP: // www.sina.com.cn ';
}
4. Prompt input box
Window. prompt
Var n = window. prompt ('enter your age', 18 );
If (n> = 18 ){
Document. write ('Welcome young people ');
}
5. control tags and output them directly on tags,
You can use document. getElementById ('id') to find the object tag. You can directly control the value and output it.
SetInterval (function () {document. getElementById ('ttt'). innerHTML = "current time:" + new Date (). toLocaleString () ;}, 1000 );
<Script>
Document. getElementById ('uname'). value = "Alias Name ";
</Script>
6. output the information directly to the title.
Document. title = "hello ";
Javascript message prompt box code I suddenly forgot the code is like this: javascript ('this is the prompt box content ')
<Script type = "text/javascript">
Alert ("this is the content of the prompt box ")
</Script>
Let me see why the javascript code cannot read the content in the input box?
Document. getElementsByName method. You can see that Elements is a complex number and an array is obtained!
GetElementByID is recommended for access with a single tag
Generally, name is used in server scripts, and ID is used in client scripts.