高手求助,动态添加删除控件!!

lonely41 2012-01-06 05:04:44
以下是我的原码!
想在表格内动态添加两个文本框,还要响应回车事件和其它事件。请高手写个代码吧!!!!!没有分了!!!
<script language=javascript src="date.js"></script>
<script language=javascript>
var c = new Calendar("c");
document.write(c);

function CheckForm()
{
if (document.myform.date1.value=="")
{alert("请选择一个有效日期!");
document.myform.date1.focus();
return false;}
if (document.myform.ks.value=="")
{alert("请选择科室!");
document.myform.ks.focus();
return false;}
if (document.myform.zyh.value=="")
{alert("请输入住院号!");
document.myform.zyh.focus();
return false;}
if (document.myform.xm.value=="")
{alert("请输入姓名!");
document.myform.xm.focus();
return false;}

}


function enterToTab()
{


if (window.event.keyCode==13)
{
window.event.keyCode=9;

}

}
</script>



<form method="POST" name="myform" onSubmit="return CheckForm();" action="Save.asp?flag=add" target="main">
<table width="90%" border="0" align="center" cellpadding="0" cellspacing="0" class="border">
<tr class="title">
<td height="22" align="center" colspan="4"><font size="4" color="#0033FF"><b>入院清单录入</b></font></td>
</tr>
<tr >
<td align="right">
<font color="#0033FF">  <strong>日期:</strong></font></td>
<td align="left"><input type="text" readonly name="date1" onFocus="c.showMoreDay = false;c.show(this);" size="10"></td>
<td align="right"><font color="#0033FF"><strong>请选择科室:</strong></font> </td>
<td align="left"><select size="1" name="ks">
<option value="1">科室1</option>
<option value="2">科室2</option>
</select>

</td>
</tr>
<tr>
<td colspan="4">
<table class="border" width="100%" id="testTbl">
<tr class="tdbg" onMouseOut="this.style.backgroundColor=''" onMouseOver="this.style.backgroundColor='#BFDFFF'" height="25" id="tr1">
<td align="center" colspan="3" id="b">
<strong> 住院号:</strong>
<input type="text" name="zyh" onKeyDown="enterToTab()" size="10" onKeyUp="value=value.replace(/[^\d]/g,'') " onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\d]/g,''))" tabindex="1" id="txt1">
   <strong>姓名:</strong>
<input type="text" name="xm" size="10" tabindex="2" onKeyDown="enterToTab()"></td>
<td align="left">
<input type="button" name="button" id="add" value="增加一行" tabindex="3" onKeyDown="enterToTab()" onclick="addRow();"></td>
</tr>
</table>
</td>
</tr>


<tr align="center">
<td colspan="4">
<div align="center">
<p>  </p>
<p>
<input name="Add" type="submit" id="Add" value=" 添 加 " onClick="document.myform.action='Save.asp?flag=add';document.myform.target='_self';" style="cursor:hand;" tabindex="40">
 
<input name="Cancel" type="button" id="Cancel" value=" 取 消 " onClick="history.go(-1)" style="cursor:hand;" tabindex="41">
</p>
</div>
</td>
</tr>
</table>
</form>

</body>
</html>
想要的效果和红字一样或者类似!!
...全文
63 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
My_ideal2010 2012-01-09
  • 打赏
  • 举报
回复
var input = document.createElement('input');
input.value="sb";
input.onclick=function(){alert('all sb')}
document.appendChild(input);

OK 了

document可以换成你要添加指定区域的 dom对象
lonely41 2012-01-09
  • 打赏
  • 举报
回复
小弟是新手,不知道如何运用JQuery,请各位大哥大姐们写出一点点来!!
win32user 2012-01-09
  • 打赏
  • 举报
回复
你看一下DHTML.chm手册,或者JQuery帮助手册,上面有示例。
xiaoliuvv 2012-01-09
  • 打赏
  • 举报
回复
<script language="javascript">
<!--
function addInput() {
var row = mytbl.insertRow();
var cell = row.insertCell();
var input = document.createElement("INPUT");
input.type = "text";
input.name="input_text";
input.setAttribute("UNSELECTABLE","on");
input.style.setAttribute("font-size","12px");
input.style.setAttribute("height","18px");
input.style.setAttribute("width","450px");
input.style.setAttribute("font-family","宋体");
input.style.setAttribute("color","#737373");
input.style.setAttribute("backgroundColor","#EEEFED");
input.style.setAttribute("border","1 solid #BBBBBA");
cell.appendChild(input); //在上一个子节点之后插入

cell = row.insertCell();
input = document.createElement("INPUT");
input.type = "button";
input.value= "删除";
input.onclick=removeInput;
input.style.setAttribute("font-size","12px");
input.style.setAttribute("font-family","宋体");
input.style.setAttribute("color","#737373");
input.style.setAttribute("backgroundColor","#ffffff");
input.style.setAttribute("border","1 solid #BBBBBA");
input.style.setAttribute("padding","1px 0px 0px 1px");
input.style.setAttribute("height","18px");
cell.appendChild(input);
}
function removeInput(){
var e = event.srcElement;
mytbl.deleteRow(e.parentElement.parentElement.rowIndex);
}
// -->
</script>
<table id="mytbl" border="0" cellpadding="0" cellspacing="0" width="100%"></table><table border="0" cellpadding="0" cellspacing="0" width="100%"><tr><td align="left"><input type="button" value="增加" onclick="addInput()" class="input_d"></td></tr></table>
lwiin6u3x 2012-01-08
  • 打赏
  • 举报
回复
直接用JQuery吧。网上示例很多的。
fictioner 2012-01-06
  • 打赏
  • 举报
回复
建议采用jQuery,可以很容易的解决很多麻烦
kris2010 2012-01-06
  • 打赏
  • 举报
回复
可用以下方式
document.getElementById("b").innerHtml
插入到<tb>中
lonely41 2012-01-06
  • 打赏
  • 举报
回复
怎么还没有人回答啊!!小弟急啊!!

28,391

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧