如何仅通过下一个和上一个按钮显示两个文本框
这是我的代码,在此代码中,当我点击下一个按钮显示两个文本框和老化时,我点击显示下两个文本框..总共四个文本框..我想每个单击只需要两个文本框.... ......我怎么能实现呢?
<script type="text/javascript">
var max=2;//highest number to go to
var currentIndex=0;
function Previous(){
if(currentIndex>0){
currentIndex--;
postClick();
}
}
function Next(){
if(currentIndex<max){
currentIndex++;
document.getElementById("div").style.display="none"
postClick();
}
}
function postClick(){//whatever you want to happen goes here
var sahan =new Array();
sahan[currentIndex]==d;
var d=document.getElementById("div");
d.innerHTML+="<p><input type='text' name='name"+currentIndex+"[]'>";
d.innerHTML+="<p><input type='text' name='topic"+currentIndex+"[]'>";
form1.text1.value=currentIndex;
}
</script>
<form name="form1">
<input type="button" value="Previous" onclick="Previous()"/>
<input type="button" value="Next" onclick="Next()"/>
</form>
<div id="div"></div>
</body>
</html>
答案 0 :(得分:2)
在postClick()函数中,尝试删除第4行的第一个“+”,即:
d.innerHTML="...";
而不是
d.innerHTML+="...";
答案 1 :(得分:0)
试试这个
<script type="text/javascript">
var max = 1; //highest number to go to
var currentIndex = 0;
function btnClick() {
if (currentIndex == 0) {
currentIndex++;
postClick();
}
}
function postClick() {//whatever you want to happen goes here
var sahan = new Array();
sahan[currentIndex] == d;
var d = document.getElementById("div");
d.innerHTML += "<p><input type='text' name='name" + currentIndex + "[]'>";
d.innerHTML += "<p><input type='text' name='topic" + currentIndex + "[]'>";
document.getElementById("div").style.display = "";
}
</script>
</head>
<body>
<form id="form1">
<div>
<input type="button" value="Previous" onclick="btnClick()" />
<input type="button" value="Next" onclick="btnClick()" />
<div id="div">
</div>
</div>
</form>