脚本部分:
function school(sName,sDddress,sPhone,sMail) { this.SName = sName; this.SAddress = sDddress; this.SPhone = sPhone; this.SMail = sMail; this.parmsArray = new Array("test1", "test2", "test3", "test4"); this.index = 0; this.SInfomation = ShowInfomation; this.trades = CreateSort; this.SAnchorUrl = AnchorUrl; } function ShowInfomation() { var msg = ""; msg += "学校名称:" + this.SName + " "; msg += "学校地址:" + this.SAddress + " "; msg += "学校电话:" + this.SPhone + " "; msg += "电子邮件:" + this.SMail; window.alert(msg); } function CreateSort() { var objArray = new Array("一年级", "二年级", "三年级", "四年级", "五年级", "六年级"); objArray.sort(function (arg1, arg2) { if (arg1.length > arg2) return false; else return true; }); window.alert(objArray.join(",")); } function AnchorUrl() { if (this.index < 3) this.index++; else this.index = 0; window.location.hash = this.parmsArray[this.index]; }
HTML部分:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> <script type="text/javascript" src="myJS.js"></script> <script type="text/javascript"> var mySchool = new school("郑州大学", "郑州高科技开发区", "0373-2323423232", "zzu@zzu.edu.cn"); </script> <style type="text/css"> p { height: 500px; text-align: center; line-height: 500px; border: solid 2px #000; font-size: 40px; font-weight: bolder; } </style> </head> <body> <center> <p><b>锚点间跳转实例</b></p> <p><a id="test1">test1</a></p> <p><a id="test2">test2</a></p> <p><a id="test3">test3</a></p> <p><a id="test4">test4</a></p> <form name="MyForm"> <input type="button" name="MyButton" value="使用hash 进行锚点转换" onclick="mySchool.SAnchorUrl()"><br> </form> </body> </html>