The Javascript alert、confirm、and prompt boxs
3837 ワード
The alert、confirm、and prompt boxs
The three「command」involved in creating alert、confirm、and prompt boxes are: window.alert() window.com nfirm() window.prompt() Lets look at them in detail.The first one is:
The second one is:
Click here for out put:
The third one is:
Click here for out put:
http://www.javascriptkit.com/javatutors/alert2.shtml
http://www.javascriptkit.com/javatutors/alert3.shtml
http://javascript.about.com/library/bldialog.htm
http://ncthakur.itgo.com/js02.htm
http://www.aspnetcenter.com/cliktoprogram/javascript/alert.asp
The three「command」involved in creating alert、confirm、and prompt boxes are:
window.alert()
This command pops up a message box displaying whatever you put in it.For example:<body>
<script type="text/javascript">
window.alert("My name is George. Welcome!")
</script>
</body>
As You can see,whatever you put inside the quot;marks,it will display it.The second one is:
window.confirm()
Confirm is used to confirm a user abot certain action、and decide between two checes depending on the user choses.Click here for out put:
<script type="text/javascript">
var x=window.confirm("Are you sure you are ok?")
if (x)
window.alert("Good!")
else
window.alert("Too bad")
</script>
The re are several concepts that are new here,and I'll go over them.First of all,"var x="is a variable declaration;declares a variable(「x」in this case)that will store the reresut of the confirm box.All variablles arcreated this way.x will get the reult、namely、「true」or「false」.The we we use the aa「stastastastastastastath th th th th th th th ath th th th th th th th th th th th th th th th th th th th th th th th th th th th th th th th th th th th th th th th th th th th th th th thethethethethetherererererererereret.x.x.eeeeeeeeeeeeededededeult is true(the user clicked「ok」)、「good」is alerted.If the result is false(the user clicked“cancel”),“Too bad”is alerted instead.(For all those interested,variable x called a boolean variable,since it can only contanight in thea value.」The third one is:
window.prompt()
Propt is used to allow a user to enter something、and do something with that info:Click here for out put:
<script type="text/javascript">
var y=window.prompt("please enter your name")
window.alert(y)
</script>
REF:
http://www.javascriptkit.com/javatutors/alert1.shtmlhttp://www.javascriptkit.com/javatutors/alert2.shtml
http://www.javascriptkit.com/javatutors/alert3.shtml
http://javascript.about.com/library/bldialog.htm
http://ncthakur.itgo.com/js02.htm
http://www.aspnetcenter.com/cliktoprogram/javascript/alert.asp