方法一: 给每个form 添加一个隐藏的字段
<form id="form1" name="form1" action="form.aspx" method="post">
<div>
<input type="text" name="Username" id="Username" />
</div>
<div>
<input type="password" name="Password" id="Password" />
</div>
<input type="hidden" name="Action" id="Action" value="form1" />
<button type="button">submit</button>
</form>
<form id="form2" name="form2" action="form.aspx" method="post">
<div>
<input type="text" name="Username" id="Username2" />
</div>
<div>
<input type="password" name="Password" id="Password2" />
</div>
<input type="hidden" name="Action" id="Action2" value="form2" />
<button type="button">submit</button>
</form>
后台区分form的方法
string formName = Request.Form("Action");
if(formName =="form1")
{
// do something
}
else if(formName =="form2")
{
// do something
}
方法二: 使用get和post混合的方法:
<form id="form1" name="form1" action="form.aspx?action=form1" method="post">
<div>
<input type="text" name="Username" id="Username" />
</div>
<div>
<input type="password" name="Password" id="Password" />
</div>
<button type="button">submit</button>
</form>
<form id="form2" name="form2" action="form.aspx?action=form2" method="post">
<div>
<input type="text" name="Username" id="Username2" />
</div>
<div>
<input type="password" name="Password" id="Password2" />
</div>
<button type="button">submit</button>
</form>
后台区分form的方法
string formName = Request.QueryString("action");
//Request.Params("action");
if(formName =="form1")
{
// do something
}
else if(formName =="form2")
{
// do something
}
本文介绍了两种在HTML中区分不同表单提交的方法:一是通过在每个表单中添加隐藏字段来标识表单名称;二是使用GET和POST混合方法,通过URL参数来区分。这两种方法在后端都可以通过读取特定的请求参数来判断表单来源。
392

被折叠的 条评论
为什么被折叠?



