各位高手帮看看:为什么我的strArray[0]存入的正确的值,而strArray[1]存入的是"Request.form["text1"],Request.form["text2"]"值?为什么不是Request.form["text2"]的值???
前台:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="RoadShow.Web.WebForm1" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div id="div1">
<input type="text" name="text1" />
<a href="javascript:CreateInputTxt();">添加新的text</a><br />
<asp:Button ID="Button1" runat="server" Text="取值" onclick="Button1_Click" />
</div>
<asp:HiddenField ID="Count" runat="server" Value="0" />
</form> <script language="javascript" type="text/javascript">
function CreateInputTxt() {
document.getElementById("Count").value++;
j = document.getElementById("Count").value;
var i = 1;
if (i < 5) {
i++;
div1.innerHTML = div1.innerHTML + "<input type='text' name='text" + i + "' style='width:270px;' MaxLength='20' ><br>";
}
if (j > 6) {
alert("多于6个失败");
}
}
</script></body>
</html>
后台:::
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;namespace RoadShow.Web
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{ } protected void Button1_Click(object sender, EventArgs e)
{
//获得text的个数
int i = int.Parse(this.Count.Value);
//Response.Write(i);
//定义个数组,用来接受text的值
string[] strArray = new string[i];
for (int j = 0; j < i; j++)
{
strArray[j] = Request.Form["text" + (j + 1).ToString()]; }
foreach (string str in strArray)
{
//测试strArray里有没有值
Response.Write(str);
}
this.Count.Value = "0";
}
}
}
前台:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="RoadShow.Web.WebForm1" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div id="div1">
<input type="text" name="text1" />
<a href="javascript:CreateInputTxt();">添加新的text</a><br />
<asp:Button ID="Button1" runat="server" Text="取值" onclick="Button1_Click" />
</div>
<asp:HiddenField ID="Count" runat="server" Value="0" />
</form> <script language="javascript" type="text/javascript">
function CreateInputTxt() {
document.getElementById("Count").value++;
j = document.getElementById("Count").value;
var i = 1;
if (i < 5) {
i++;
div1.innerHTML = div1.innerHTML + "<input type='text' name='text" + i + "' style='width:270px;' MaxLength='20' ><br>";
}
if (j > 6) {
alert("多于6个失败");
}
}
</script></body>
</html>
后台:::
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;namespace RoadShow.Web
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{ } protected void Button1_Click(object sender, EventArgs e)
{
//获得text的个数
int i = int.Parse(this.Count.Value);
//Response.Write(i);
//定义个数组,用来接受text的值
string[] strArray = new string[i];
for (int j = 0; j < i; j++)
{
strArray[j] = Request.Form["text" + (j + 1).ToString()]; }
foreach (string str in strArray)
{
//测试strArray里有没有值
Response.Write(str);
}
this.Count.Value = "0";
}
}
}
解决方案 »
- easyui的datagrid,指定的一列值非空,该列非空的那一行背景色改变
- 请教一下js如何实现点button 在线播放mp3?
- 问一个问题,解决了130分(有另一贴100分)
- 可以用JS模拟一个鼠标事件吗?
- 怎样用js引入word内容到htmledit中?急需
- 网页上有一张图片,我能否在上面用鼠标托出一个虚线框(实线也可以),并返回托动线框在这张图片上的相对坐标?
- ssm1226(雨中人)进来取分
- IE6下的document.body=null,这是为什么?
- 代码的执行效率的讨论.
- 经jquery的Dialog 插入图片至 ckeditor
- javascript多级互联菜单
- javascript中这两种写法的作用的区别
{
string textid = "text" + (j + 1).ToString();
strArray[j] = Request.Form[textid];
}
你这样做试一试!