JS学习---(一)

来源:互联网 发布:thinking in java 4th 编辑:程序博客网 时间:2024/05/20 21:44

1.确认消息对话框 confirm

<!DOCTYPE HTML><html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>confirm</title>  <script type="text/javascript">  function rec(){    var mymessage=confirm("你喜欢jS不?")         ;    if(mymessage==true)    {        document.write("你喜欢!");    }    else    {        document.write("你不喜欢!");    }  }      </script></head><body>    <input name="button" type="button" onClick="rec()" value="点击我,弹出确认对话框" /></body></html>

2. 提问消息框prompt

<!DOCTYPE HTML><html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>prompt</title>  <script type="text/javascript">  function rec(){    var score; //score变量,用来存储用户输入的成绩值。    score = prompt("请输入你的成绩:")               ;    if(score>=90)    {       document.write("你很棒!");    }    else if(score>=75)    {       document.write("不错吆!");    }    else if(score>=60)    {       document.write("要加油!");    }    else    {       document.write("要努力了!");    }  }  </script></head><body>    <input name="button" type="button" onClick="rec()" value="点击我,对成绩做评价!" /></body></html>

3.打开新窗口
window.open([URL], [窗口名称], [参数字符串])

<!DOCTYPE HTML><html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>window.open</title><script type="text/javascript">  function Wopen()  {    window.open("http://www.baidu.com","_blank");  } </script></head><body>    <input name="button" type="button" onClick="Wopen()" value="点击我,打开新窗口!" / ></body></html>

4.关闭窗口 window.close();—关闭本窗口;<窗口对象>.close();
5.结合了上面小方法的一个综合程序

<!DOCTYPE html><html> <head>  <title> new document </title>    <meta http-equiv="Content-Type" content="text/html; charset=gbk"/>     <script type="text/javascript">      function openWindow()    {        var mymessage=confirm("是否打开");        if(mymessage==true)        {            var wangzhi; //            wangzhi = prompt("请输入你的网址:","http://www.imooc.com");            myWindow=window.open(wangzhi,"_blank","width=400,height=500");        }        else        {            document.write("都不要了,还怎么玩");        }   }    // 新窗口打开时弹出确认框,是否打开    // 通过输入对话框,确定打开的网址,默认为 http://www.imooc.com/    //打开的窗口要求,宽400像素,高500像素,无菜单栏、无工具栏  </script>  </head>  <body>       <input type="button" value="新窗口打开网站" onclick="openWindow()" />  </body></html>
0 0
原创粉丝点击