1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > 使用js动态添加文本框 并在后台取文本框数据

使用js动态添加文本框 并在后台取文本框数据

时间:2023-08-20 21:29:34

相关推荐

使用js动态添加文本框 并在后台取文本框数据

js部分

<script language="javascript" type="text/javascript">

var count=0 ;

function additem(id)

{

var row,cell,str;

row = document.getElementById(id).insertRow(count+1);

if(row != null )

{

row.insertCell(0).innerHTML="";//"<td align=\"right\": style=\"border-left-style: none; border-left-width: medium; border-top-style: none; border-top-width: medium;\">处罚依据:</td> ";

row.insertCell(1).innerHTML="<td style=\"border-left-style: none; border-left-width: medium; border-top-style: none; border-top-width: medium;\" colspan=\"3\"><input style=\"width:420px\" id=\"St"+count+"\" type=\"text\" name=\"St"+count+"\"> </td>";//<input type=\"button\" class=\"button\" value=\"删除\" οnclick=\'deleteitem(this);\'>

count ++;

}

}

//function deleteitem(obj)

//{

// var curRow = obj.parentNode.parentNode;

// tb.deleteRow(curRow.rowIndex);

//}

function getsub()

{

var re="";

for (var i = 0 ;i<count;i++)

{

re += document.getElementsByName("St"+i)[0].value+"</br>";

}

document.getElementById("Hidvalue").value=re;

//document.getElementById("Hidhtml").value = document.getElementById("tb").innerHTML;

}

</script>

动态生成位置的table

<table id="tb" border="1" width="100%" bordercolor="#000033" >

<tr>

<td align="right" width="120px" style=" border:none;">

处罚依据:</td>

<td colspan="3" style=" border-left-style: none; border-left-width: medium; border-top-style: none; border-top-width: medium;">

<asp:TextBox ID="Txt_cfyj" runat="server" MaxLength="50" Width="65%"></asp:TextBox>

<a style="color: Red;">*</a><asp:RequiredFieldValidator ID="RequiredFieldValidator6" runat="server" ControlToValidate="Txt_cfyj" ErrorMessage=""></asp:RequiredFieldValidator>

<input class="button" name="button" οnclick='additem("tb")' type="button" value="添加" />

</td>

</tr>

</table>

使用的部分:

string aa = Request.Form["Hidvalue"];

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。