我想实现按一按button实现表格的行数再增加一行,接del删除增加的一行,如何实现?

nbjed 2004-11-05 05:10:13
我想实现按一按button实现表格的行数再增加一行,接del删除增加的一行,如何实现?
...全文
118 4 打赏 收藏 举报
写回复
4 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
stefli 2004-11-05
  • 打赏
  • 举报
回复
http://www.51windows.net/hw/asp/jsview.asp?id=18
nbjed 2004-11-05
  • 打赏
  • 举报
回复
非常感谢!
hary90 2004-11-05
  • 打赏
  • 举报
回复
其实代码没有怎么复杂,里面有我以前做的那些调试代码,你可以把他清除吧
hary90 2004-11-05
  • 打赏
  • 举报
回复
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<SCRIPT LANGUAGE="JAVASCRIPT">
function Add(oTable,TextSave){
alert(TextSave)
var intTRsLength = oTable.firstChild.children.length;
var oTbody = oTable.firstChild;
var newTR = document.createElement("TR");
var newTD1 = document.createElement("TD");
newTD1.setAttribute("align","center");
newTD1.innerHTML = "<INPUT TYPE='CHECKBOX' ID='Select"+ (intTRsLength+1) +"' Authod='hary' style='border:0;background-color:#F3F3F5'>";
var newTD2 = document.createElement("TD");
newTD2.innerHTML = "<INPUT TYPE='TEXT' ID='SortName'"+ (intTRsLength+1) +"' STYLE='BORDER:0;background-color:#F3F3F5;width:100%' onfocus=\"this.style.border=\'solid 1px blue\'\" onblur=\"this.style.border=\'0\';SaveParam(oTable,TextSave)\">"
newTR.appendChild(newTD1);
newTR.appendChild(newTD2);
oTbody.appendChild(newTR);
newTD2.firstChild.focus();

}
function Del(form){
var oTbody = oTable.firstChild;
var intTRsLength = oTbody.children.length-1;
//减去children(0)(TH)
for(var i=intTRsLength;i>=1;i--){
//取得checkbox对象
var oCheckbox = oTbody.children(i).firstChild.firstChild;
if(oCheckbox.checked==true && oCheckbox.Authod=="hary"){
var oDelTR=oTbody.children(i);
oTbody.removeChild(oDelTR);
}
}
}
function DetachParam(Params){
if(Params=="")return false;
Params+=";";
var intLength=Params.length;
var intParamCount = 0;
for(var i=0;i<intLength;i++){
if(Params.substring(i,i+1)==";"){
intParamCount++
}
}
var arrParam = new Array(intParamCount);
var arrTempPosition = new Array(intParamCount);
arrTempPosition[0]=-1;
for(var i=0;i<intParamCount;i++){
arrTempPosition[i+1] = Params.indexOf(";",arrTempPosition[i]+1);
arrParam[i] = Ltrim(Params.substring(arrTempPosition[i]+1,arrTempPosition[i+1]));
}
return arrParam;
}
function Ltrim(Getstring){
var intStringLength = Getstring.length;
var isSpace = true;
var newString="";
for(var i=0;i<intStringLength;i++){
if(Getstring.substring(i,i+1)==" " && isSpace==true){
continue;
}
if(Getstring.substring(i,i+1)!=""){
newString+=Getstring.substring(i,i+1);
isSpace=false;
}
}
return newString;
}

function GetParam(getString,oTalbe,TextSave){
var arrParam=DetachParam(getString);
var intLength =arrParam.length
var oTbody = oTable.firstChild;
for(var i =0 ; i<intLength ; i++){
var oTr = document.createElement("TR");
var oTd1 = document.createElement("TD");
oTd1.setAttribute("align","center");
oTd1.innerHTML = "<INPUT TYPE='CHECKBOX' ID='Select"+ intLength+1 +"' Authod='hary' style='border:0;background-color:#F3F3F5'>";
var oTd2 = document.createElement("TD");
oTd2.innerHTML = "<INPUT TYPE='TEXT' ID='SortName'"+ intLength+1 +"' value='"+ arrParam[i] +"' STYLE='BORDER:0;background-color:#F3F3F5;width:100%' onfocus=\"this.style.border=\'solid 1px blue\'\" onblur=\"this.style.border=\'0\';SaveParam(oTable,TextSave)\">"
oTr.appendChild(oTd1);
oTr.appendChild(oTd2);
oTbody.appendChild(oTr);
}
}

function SaveParam(oTable,TextSave){
var intTRsLength = oTable.firstChild.children.length-1;
var Params = "";
for(var i=1 ;i<=intTRsLength;i++){
var oTr = oTable.firstChild.children(i);
var oTd = oTr.children(1);
if(i==intTRsLength)
Params+=oTd.firstChild.value;
else
Params+=oTd.firstChild.value +";";
}
TextSave.value = Params;
}
</SCRIPT>

</HEAD>

<BODY onload="GetParam(document.forms[0].GetValue.value,document.all.oTable,document.forms[0].GovAffair_TextSave)">
<FORM>
<TABLE ID="oTable" BORDER="1">
<TR><TH>选择</TH><TH>信息分类</TH><TH disabled><A href="#" onclick="alert(this.type)">fdfdf</A></TH></TR>
</TABLE>
<input type="button" name="addButton" value="添加" onclick="Add(oTable,document.forms[0].GovAffair_TextSave)"><input type="button" name="delButton" value="删除" onclick="Del(this.form)">
<input type="text" value="SONY; IBM; ASUS" Name="GetValue" ReadOnly Style="display:none"><input type="button" value="保存更新" onclick="SaveParam(oTable,document.forms[0].GovAffair_TextSave)">
<input type="test" name="GovAffair_TextSave" id="TextSave">
</FORM>
</BODY>
</HTML>
发帖
JavaScript

8.7w+

社区成员

Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
帖子事件
创建了帖子
2004-11-05 05:10
社区公告
暂无公告