我有一個我的同事建立的javascript數組代碼。我已經解決了這個問題,所以根據你選擇的複選框,它會去指定的頁面(zero.html。zeroone.html等)。我現在想要完成的是,當你選擇多個複選框時,它會根據選中的複選框轉到另一個頁面。Javascript複選框有多個選擇結果的數組
這裏是我們的代碼:
<script language="javascript">
<!-- Activate Cloaking Device -->
// Set in dataBase() function - used as array index.
var recnum="";
// Used to initialize arrays.
function initArray()
{
this.length = initArray.arguments.length;
for (var i = 0; i < this.length; i++)
{ this[i] = initArray.arguments[i]; }
}
// Creating the arrays
var rcrd = new initArray();
var address = new initArray();
address[0] = "zero.html";
address[1] = "one.html";
address[2] = "two.html";
address[0,1] = "zeroone.html";
address[0,2] = "zerotwo.html";
address[1,2] = "onetwo.html";
address[0,1,2] = "zeroonetwo.html";
// Called by onClick for each checkbox button - determines & displays url in full window
function dataBase(leapto)
{
for (var i = 0; i < 4; i++)
{
if (leapto.buttons[i].checked)
{ recnum = leapto.buttons[i].value; }
}
if ((rcrd[recnum] !=null) && (rcrd[recnum] != ""))
{ document.leapto.display.value = rcrd[recnum]+"\r\n\r\n"+address[recnum]; }
}
// Called by Search Now button - Loads preselected page.
function leapTo()
{
if ((address[recnum] !=null) && (address[recnum] != "") && (recnum != ""))
window.location= address[recnum];
else
alert("\nYou must make a selection first.");
}
// Deactivate Cloaking
</script>
</head>
<body>
<form name="leapto">
<input type="checkbox" name="buttons" value="0" onclick="dataBase(this.form)" /> Zero<br />
<input type="checkbox" name="buttons" value="1" onclick="dataBase(this.form)" /> One<br />
<input type="checkbox" name="buttons" value="2" onclick="dataBase(this.form)" /> Two<br />
<input type="button" class="classname" width="400" height="50" border="0" value="Search Now" onclick="leapTo()" /></form>
<script>
function myFunction(){var x;if (name!=null) {document.getElementById("demo").innerHTML=x;}}
</script>
</body>
順便說一句,我們都不需要自1997年左右古 –
習慣腳本僞裝,多爲我的筆記 – mark1178