web技术概论第六周作业

来源:互联网 发布:java 报表工具 开源 编辑:程序博客网 时间:2024/06/13 11:22

Homework 0:
JavaScript Browser Sniffer is a browser identifier written in JavaScript (EcmaScript) and released under the LGPL license. It will tell which browser, version and operating system you (the visitor) are using. It also detects bots and the Flash plugin.
JavaScript browser sniffers are widely used because of the incompatibilities between browsers. Different browsers have different ways understanding the same code written by Javascript. As a result, different browsers will display the same page differently. Javascript browser sniffers detect what web browser a user is working with so as to ensure consistent display of content.

Homework 1: hiThere.html
So easy ~ 赵老师再也不用担心我的学习= =

Homework 2: function.html

  1. 简单的js运算操作,添加result = result * 2; 即可
  2. 简单的js函数实现。代码段如下:
    function StrCatenate(astr, bstr) { cstr = astr+" != "+bstr; return cstr; }

Homework 3: popups.html

  1. 根据弹出框的输入重定向页面,修改页面的location属性。代码见askName()函数。这里需要注意如果简单的将location改为“baidu.com”是无法跳转的,因为默认href为相对路径。输入前需要加上http等协议名。
    当然,为了简化用户操作,我在函数中添加了自动的验证,即使输入不带协议头的路径,也可以正确跳转。
  2. the Lemon 后面添加 return 就可以了。
    这里的status bar其实有点过期啊,我的电脑上只有chrome和firefox。结果网上查询的结果是

The new Firefox Status Bar only shows page loading activity and link previews. When neither of those are needed it simply disappears.The old Status Bar is dead, long live Status-4-Evar!

There’s no status bar in Chrome. The old toolstrip(on the bottom part of the browser) is eliminated in current versions of Chrome. Maybe you can try the switch but I guess it’s virtually useless since no current extensions now utilize that part of the UI.

郁闷死了==卡了半天,最后我在linux上安装了一个IE6,终于在左下角看到了status bar。真的是在linux上安装的,有图有真相!(statusbar.png)

Homework 4: objects.html

  1. 简单的全局数组变量操作var HolidayList = [ ];
  2. 2&3&4:简单的js类操作。代码如下:
 function makeHoliday(dest, dur, cost) {         hol = new Holiday(dest, dur, cost);         HolidayList.push(hol);     }
  function outputObject(anObject) {         for (f in anObject) {           document.write(f + " = " + anObject[f] + "<br />");         }      }

Homework 5: wizardForm.html

  1. 检测年龄并且限制年龄的大小。检测数字主要使用js自带的正则表达式。检测大小用eval进行数字之间的比较。

  2. checkSubmit()阻塞提交其实与其返回值有关。如果返回true,表单会继续提交,返回false则停止提交。这种特性正好可以用于上面的检测函数。通过检测则提交,否则不提交。详细可见checkSubmit()函数。

  3. 另外,同样添加了其他几个测试函数checkName,checkID,限制输入值的字符。
function checkAge(q) {    var reg = /^\d+$/;             if (!reg.test(q.Personal_Age.value)) {          return false;    }    if(eval(q.Personal_Age.value)<=5 ||    eval(q.Personal_Age.value)>=150) {        return false;    }    return true;}
0 0
原创粉丝点击