有2个按钮,增加,删除
按增加出现:
1 checkbox1 textbox1 button1 textbox2 button2 textbox3 button3........
增加按钮
2 checkbox2 textbox1 button1 textbox2 button2 textbox3 button3........
。
。
。
我选择checkbox2 则删除第2行。。
请问如何用javascript实现此功能,并如何把数据存到数据库中?是在asp.net环境中
谢谢!!!
按增加出现:
1 checkbox1 textbox1 button1 textbox2 button2 textbox3 button3........
增加按钮
2 checkbox2 textbox1 button1 textbox2 button2 textbox3 button3........
。
。
。
我选择checkbox2 则删除第2行。。
请问如何用javascript实现此功能,并如何把数据存到数据库中?是在asp.net环境中
谢谢!!!
cellSpacing="0" cols="6" cellPadding="1" bgColor="#eeeeee" border="1" borderColor="#cccccc">
<THEAD>
<TR style="FONT-WEIGHT: bold; FONT-SIZE: 10pt; COLOR: #ffffff; BACKGROUND-COLOR: #eeeeee"
align="center" bgColor="#003399">
<TD style="WIDTH: 203px" width="203">
<P>客户名称</P>
</TD>
<TD style="WIDTH: 201px" width="201">产品名称</TD>
<TD width="32">单位</TD>
<TD style="WIDTH: 65px" width="65">单价</TD>
<TD style="WIDTH: 54px" width="54">数量</TD>
<TD width="100">金额</TD>
</TR>
</THEAD>
<TR>
<TD style="WIDTH: 203px"><INPUT id="customerCode" style="WIDTH: 0px" readOnly type="hidden" maxLength="50" name="customerCode">
<INPUT id="customerName" style="WIDTH: 160px; HEIGHT: 19px; BACKGROUND-COLOR: #e0e0e0"
readOnly size="14" name="customerName"> <INPUT id="btncustomer" title="选择客户" onclick="ButtonSelectCutomer_onclick()" type="button"
value="...">
</TD>
<TD style="WIDTH: 201px"><INPUT id="productCode" style="WIDTH: 0px" readOnly type="hidden" maxLength="50" onchange="Count_Product_Money()"
size="0" name="productCode"><INPUT id="productName" style="WIDTH: 160px; BACKGROUND-COLOR: #e0e0e0" readOnly type="text"
maxLength="200" name="productName"><INPUT id="btgetproductCode" title="选择产品" onclick="SelectproductCode()" type="button" value="...">
</TD>
<TD><INPUT id="unit" style="WIDTH: 40px; BACKGROUND-COLOR: #e0e0e0; TEXT-ALIGN: right" readOnly
type="text" maxLength="20" name="unit"></TD>
<TD style="WIDTH: 65px"><INPUT id="price" style="WIDTH: 70px; BACKGROUND-COLOR: #e0e0e0; TEXT-ALIGN: right" readOnly
type="text" maxLength="100" onchange="Count_Product_Money()" name="price"></TD>
<TD style="WIDTH: 54px"><INPUT id="number" style="WIDTH: 70px; TEXT-ALIGN: right" onfocus="getfocus()" type="text"
maxLength="100" onchange="Count_Product_Money()" name="number"></TD>
<TD><INPUT id="money" style="WIDTH: 100px; BACKGROUND-COLOR: #e0e0e0; TEXT-ALIGN: right" readOnly
type="text" maxLength="20" name="money"></TD>
</TR>
</TABLE>脚本如下:<script language="javascript" id="clientEventHandlersJS">
<!--var currentrowindex = null,prerowindex = null; //定义表格选择的当前行[currentrowindex].cells[0].children[1].title = str[1];//增加行按钮事件
function InputAddProduct_onclick() {
var newrow = DataGrid2.insertRow();
for(var i=0;i<DataGrid2.cols;i++)
{
newrow.insertCell();
newrow.cells[i].innerHTML = DataGrid2.rows[DataGrid2.rows.length-2].cells[i].innerHTML;
}
}//删除行按钮事件
function InputDeleteProduct_onclick() {
if((currentrowindex != null) && (DataGrid2.rows.length > 2))
{
DataGrid2.deleteRow(currentrowindex);
currentrowindex = null;
All_Money();
}
else if(DataGrid2.rows.length ==2)
{
alert('不能删除最后一行!');
}
}//将选中行置背景色
function selectRow()
{
if(prerowindex != null)
DataGrid2.rows[prerowindex].bgColor = "#FFFFFF";
if(currentrowindex != null)
{
DataGrid2.rows[currentrowindex].bgColor = "#808080";
}
}function DataGrid2_onclick()
{
if ((window.event.srcElement.tagName == "TD") && (window.event.srcElement.parentElement.rowIndex != 0))
{
prerowindex = currentrowindex;
currentrowindex = window.event.srcElement.parentElement.rowIndex;
}
if (window.event.srcElement.tagName == "BODY")
{
return null;
}
if(window.event.srcElement.tagName == "INPUT")
{
prerowindex = currentrowindex;
currentrowindex = window.event.srcElement.parentElement.parentElement.rowIndex;
}
selectRow();
}//得到行焦点
function getfocus()
{
if(window.event.srcElement.tagName == "INPUT")
{
prerowindex = currentrowindex;
currentrowindex = window.event.srcElement.parentElement.parentElement.rowIndex;
}
selectRow();
}//-->
</script>
基本上 做不大的改动即可满足你的需求
就是添加按钮则自动添加一行,里面有文本框等删除同理
问题是我提交的时候如何来取值,因为页面包含了其它的web控键txt.text。
request.param?
一般有两种方式
一种是传几个参数到另外的页面处理(C#)另一种方式就是用aspnet的SetPostback属性