我有 2 个数组和一个变量。我可以将一个项目推送到一个变量中,然后再次单击,将其添加到一个数组中。但是,我有另一个按钮,可以将该数组中的一个项目移回变量中,然后将变量移动到另一个数组中。我的代码适用于第一部分,但是我的函数现在确实加载了第二部分,请问有什么帮助吗?
这部分似乎不起作用
<INPUT type=button value="Back" onClick='txtPop.value = popBackStack();showStack(theList);pushForStack(curUrl);
showStack2(theList2);'>
整个代码如下:
<SCRIPT>
var backStack = new Array();
var forStack = new Array();
var curUrl = document.getElementById("txtPop");
function pushStack(newVal) {
backStack.push(curUrl);
curUrl = newVal;
}
function pushForStack(newVal) {
CurUrl = newVal;
forstack.push(curUrl);
}
function popBackStack() {
var popVal = backStack.pop();
if (popVal == undefined) return "Nothing left!";
else return popVal
}
function popForStack() {
var popVal = forStack.pop();
if (popVal == undefined) return "Enter a new URL";
else return popVal;
}
function showStack(theSelect) {
theSelect.options.length = 0;
for (var i = 0; i < backStack.length; i++) {
var theOption = new Option(backStack[i]);
theSelect.options[theSelect.options.length] = theOption;
}
}
function showStack2(theSelect) {
theSelect.options.length = 0;
for (var i = 0; i < forStack.length; i++) {
var theOption = new Option(forStack[i]);
theSelect.options[theSelect.options.length] = theOption;
}
}
</SCRIPT>
<table width="104%" height="364" border="5" cellpadding="3" cellspacing="3">
<tr>
<th width="30%" height="78" scope="col"><p>
<INPUT type=button value="Back" onClick='txtPop.value = popBackStack();showStack(theList);pushForStack(curUrl);
showStack2(theList2);'></p></th>
<th width="46%" scope="col"><p>
<center>
<INPUT type=text name=txtPush>
<INPUT type=button value="Push" onClick='pushStack(txtPush.value);txtPush.value="";txtPop.value = curUrl; showStack(theList);'>
</center>
</p></th>
<th width="24%" scope="col"><p><INPUT type=button value="Forward" onClick="txtPop.value = popBackStack();showStack2(theList2);"></p></th>
</tr>
<tr>
<td><p><center>
<SELECT name="theList" size=12>
</SELECT>
</center></p></td>
<td><p><center><INPUT type=textki name=txtPop size=25></center></p></td>
<td><center>
<SELECT name="theList2" size=12>
</SELECT>
</center></td>
</tr>
</table>