javascript当中prompt的用法

马克- to-win:马克 java社区:防盗版实名手机尾号: 73203。



例 1.5(promptIEFF.html)


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<style type="text/css">
#divTest{
background-color:#9F3;
/*没有底下的margin为负,fireFox中老有个白边*/
margin-top:-8px;
margin-left:-8px;
width:500px;
height:500px;
}
</style>
</head>
<body>
<div id="divTest">
    body div
</div>
</body>
<script language="javascript" type="text/javascript">
 /* 返回值:Property/method value type:    String primitive
  JavaScript syntax:    -    myResult = myWindow.prompt(aString, aDefaultValue)
  -    myResult = prompt(aString, aDefaultValue)
  Argument list:    aDefaultValue    An initial content for the text box
  aString    Some text to explain what to enter

  马克-to-win:for Prompt: If the Cancel button is clicked, the method will return null instead.
also the retun type is string.
*/
 var bg=prompt("您喜欢那一种背景色:\n浅蓝 ->2,浅红 -> 1","1");
alert(typeof(bg));
alert("bg is"+bg);
  //document.body.style.backgroundColor=color;
 /*bg是string, 但是==只看值是否相等*/
       if          (bg == 1)    {
       document.getElementById("divTest").style.backgroundColor="red"; }
       else if  (bg == 2)    {
       document.getElementById("divTest").style.backgroundColor="blue"; }
       else if  (bg == null)    {
       document.getElementById("divTest").style.backgroundColor="yellow"; }

</script>
</html>