日期:2014-05-16 浏览次数:20332 次
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>无标题文档</title> <style> div{display:none;} </style> <body> <div> <input type="text" /> <input type="text" /> </div> <div> <input type="text" /> <input type="text" /> </div> <div> <input type="text" /> <input type="text" /> </div> <input type="button" value="click me" id="btn" /> <script type="text/javascript"> var divs = document.getElementsByTagName('div'); var count = 0; document.getElementById('btn').onclick = function(){ if(divs[count]){ divs[count].style.display = 'block'; count++; } }; </script> </body> </html>
------解决方案--------------------
<!DOCTYPE html> <html> <head> <script src="jquery162.js"></script> </head> <body> <input type="button" value="点击添加" onclick="show()"/> <hr style="display:none"/> <input type="text" style="display:none" id="txt"/> <input type="text" style="display:none" id="txt"/> <hr style="display:none"/> <input type="text" style="display:none" id="txt"/> <input type="text" style="display:none" id="txt"/> <hr style="display:none"/> <input type="text" style="display:none" id="txt"/> <input type="text" style="display:none" id="txt"/> <input type="button" value="点击隐藏" onclick="hide()"/> <script> var i=1; var texts=document.getElementsByTagName('input'); var hrs=document.getElementsByTagName('hr'); function show(){ if(i<=6){ var j=(i-1)/2; hrs[j].style.display='block'; texts[i].style.display='block'; texts[++i].style.display='block'; i++; } } function hide(){ if(i>2){ j=(i-2)/2; hrs[j].style.display='none'; texts[--i].style.display='none'; texts[--i].style.display='none'; } } </script> </body> </html>