我想用javascript编写一个栈程序.
我在<html>中加入<input type="text" name=text1>和<input type="text" name=text2>连个文本框和入栈,出栈清空三个按钮.
我想请问我如何实现在text1文本里面输入的数字入栈,而出栈得数字在text2里输出呢.
我是一个初学者,还望大家多多帮忙啊~~~
我在<html>中加入<input type="text" name=text1>和<input type="text" name=text2>连个文本框和入栈,出栈清空三个按钮.
我想请问我如何实现在text1文本里面输入的数字入栈,而出栈得数字在text2里输出呢.
我是一个初学者,还望大家多多帮忙啊~~~
解决方案 »
- 字符串中插入字符串,和寻找最大数的问题
- 请教extjs的combobox,输入联想如何支持中文
- JavaScript能连续跳转页面吗?
- 如何利用JavaScript获取其他页面中的一个table
- 一个简单的innerHTML问题,不知道错哪里了??请指教!
- 用javascript+xml 写了个菜单,偶尔会出现Internet Explorer不能打开站点,operation abort
- 急,哪位高手进来帮忙看看,一个不简单的简单问题,解决立刻给分
- 如何能做到这样的功能???
- 请问,javascript生成的数据如何加密,以防止用户仿冒?
- 关于控制滚动条移动的问题
- 网页刷新问题
- 获取动态创建元素的值的方法
<html xmlns="http://www.w3.org/1999/xhtml"><head>
<meta http-equiv="content-type" content="text/html; charset=gb2312" />
<title>hi,csdn</title>
<script>
function stack(){
this.data = new Array();
this.start = -1;
this.push = function(i){
this.data[this.data.length] = i;
}
this.pop = function(){
this.start++;
if(this.start==this.data.length){
this.start--;
return "out of stack";
}
return this.data[this.start];
}
this.clear = function(){
this.data = new Array();
this.start = -1;
}
}
var newstack=new stack();
</script>
</head><body>
<input id="a" type="text">
<input id="b" type="text">
<input type="button" value="in" onclick="newstack.push(a.value);a.value=''">
<input type="button" value="out" onclick="b.value=newstack.pop()">
<input type="button" value="clear" onclick="newstack.clear()">
</body></html>