代码改变世界

学习Web开发写的第一个js脚本

2007-03-22 14:03  flyingfish  阅读(670)  评论(0编辑  收藏  举报

刚接触Web开发,好几天了不知道从哪里下手,仔细想了一下原因大概如下:

1)、不了解web应用运行的详细模型和流程,就是原理问题。

2)、一时没分清楚网页和web应用的关系,比如用ASP.net时分不清楚是么时候用HTML标记,什么时候用web control。

3)、其实写代码倒不是问题,Web开发有一些有别于WinForm开发的特殊对象和编程规范。像session,cookie,response,document等。

感觉要能有质的突破,需要深刻理解以上关键点。

今早手工编写了第一个HTML脚本,建立起基本概念。

<HTML>     <head>         <script language="javascript">             //改变网页内容             function changeContent(document,num)             {              if(num==1)              {                  for(i=1;i<100;i++)                  {                     document.write(i+"<br>");                  }                               document.bgColor = "red";                                    }              if(num==2)              {                     for(i=1;i<100;i++)                     {                      document.write(100-i+"<br>");                     }                                     document.bgColor = "yellow";              }                          }                   //-------------------------------------------------------------------------             //弹出窗口             function popWindow()             {              pop_win=open("http://www.sohu.com","sohu","top=100,left=100,width=100,height=100");              return str;             }                      //-------------------------------------------------------------------------                         //状态栏滚动文字介绍             //自左向右,循环滚动             function Helpor_net(seed)             {                 var m1 = "你要显示的文字,如:欢迎来到晓寒工作室" ;                 var m2 = "" ;                 var msg=m1+m2;                 var out = " ";                 var c = 1;                 var speed = 120;                 if (seed > 100)                 {                     seed-=2;                     var cmd="Helpor_net(" + seed + ")";                     timerTwo=window.setTimeout(cmd,speed);                 }                 else if (seed <= 100 && seed > 0)                 {                     for (c=0 ; c < seed ; c++)                     { out+=" ";}                     out+=msg;                     seed-=2;                     var cmd="Helpor_net(" + seed + ")";                     window.status=out;                     timerTwo=window.setTimeout(cmd,speed);                 }                 else if (seed <= 0)                 {                     if (-seed < msg.length)                     {                         out+=msg.substring(-seed,msg.length);                         seed-=2;                         var cmd="Helpor_net(" + seed + ")";                         window.status=out;                         timerTwo=window.setTimeout(cmd,speed);                     }                     else                     {                         window.status=" ";                         timerTwo=window.setTimeout("Helpor_net(100)",speed);                     }                 }             }             Helpor_net(100);         </script>     </head>      <body>     <center>             <div><input type=button value=按钮1 onclick=changeContent(document,1);></div>         <div><input type=text value=text1 onselect=alert("text1");></div>         <div><input type=text value=text2 onfocus=alert("text2");></div>         <div>         <select type=select name=combobox onChange=comboxChanging();>             <option value=a>111</option>             <option value=b>222</option>             <option selected value=c>333</option>                     </select>         </div>     </enter>          <br>          <div>         <input type=button value=按钮2 onclick="f2(document,2);">     </div>              <div>         <input type=button value=弹出窗口 onclick="pop_window=popWindow();">         <br>         <input type=button value=关闭窗口 onclick="pop_window.close();">     </div>              <script>         function comboxChanging()         {             alert("你选择了"+combobox.value);         }     </script>      </body> </html>