javascript输出html标签问题(100分求)
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
</HEAD>
<BODY>
<FORM METHOD=POST ACTION= "Noname3.html ">
</FORM>
<INPUT TYPE= "text " NAME= "AA " id= "AA " >
<INPUT TYPE= "submit " onclick = "Test(AA.value) ">
<HR>
<!-- 想在 <HR> 后面再画a-1的 <HR> . 这样似乎不可以呀!-->
<SCRIPT LANGUAGE= "JavaScript ">
<!--
function Test(a)
{
var tmp = a-1;
if (tmp > 0)
{
while (tmp > 0)
{
document.write( " <hr> ");
tmp--;
}
}
}
//-->
</SCRIPT>
</BODY>
</HTML>
文本输入 3 ,点提交!
想实现 在本页面后面再画 3-1 个横线 <hr> 了
现在的程序画了!却把以前的文本和横线覆盖了
怎么可以亚!
------解决方案-------------------- <HTML>
<HEAD>
<TITLE> New Document </TITLE>
<!-- 想在 <HR> 后面再画a-1的 <HR> . 这样似乎不可以呀!-->
<SCRIPT LANGUAGE= "JavaScript ">
<!--
function Test(a)
{
var tmp = a-1;
if (tmp > 0)
{
while (tmp > 0)
{
//document.write( " <hr> ");
var o=document.getElementById( "a ");
alert(o);
var t=document.createElement( "hr ");
o.appendChild(t);
tmp--;
}
}
}
//-->
</SCRIPT>
</HEAD>
<BODY>
<INPUT TYPE= "text " NAME= "AA " id= "AA " >
<INPUT TYPE= "button " onclick = "Test(AA.value) " value= "add ">
<HR id= "hr1 ">
<div id= "a ">
</div>
</BODY>
</HTML>
------解决方案--------------------可以在div里画:
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
</HEAD>
<BODY>
<FORM METHOD=POST ACTION= "Noname3.html ">
</FORM>
<INPUT TYPE= "text " NAME= "AA " id= "AA " >
<INPUT TYPE= "submit " onclick = "Test(AA.value) ">
<HR>
<div id= "draw_hr "> </div>
<!-- 想在 <HR> 后面再画a-1的 <HR> . 这样似乎不可以呀!-->
<SCRIPT LANGUAGE= "JavaScript ">
<!--
function Test(a)
{
var tmp_html= " ";
for (var tmp=1; tmp <a; tmp++)
{
tmp_html+= " <hr> ";
}
draw_hr.innerHTML=tmp_html;
}
//-->
</SCRIPT>
</BODY>
</HTML>