JavaScript対象に向けて+Arayの使い方と文字列の組合せ+ダイナミックにアンカーポイントを設定します.
15075 ワード
スクリプト部分:
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",
"[email protected]");
</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>