div A,B可以用2个form吧? 那么你用js判断时传入相应的form就是了。 比如 div A form A input x onclick="javascript:fun_name(this.x.value)" ..... div B form B input x onclick="javascript:fun_name(this.x.value)"
我个人认为可以通过判断div的style属性来判断 校验div A还是div B,下面是我自己做的一个小例子,希望能帮到你 <!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> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>无标题文档</title> <script language="javascript"> function checkValue() { if(document.getElementById("a").style.display=='block') { if(document.getElementById("txt1").value=="") { alert('txt1 not null'); } } if(document.getElementById("b").style.display=='block') { if(document.getElementById("txt2").value=="") { alert('txt2 not null'); } }
比如
div A
form A
input x onclick="javascript:fun_name(this.x.value)"
.....
div B
form B
input x onclick="javascript:fun_name(this.x.value)"
<!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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script language="javascript">
function checkValue()
{
if(document.getElementById("a").style.display=='block')
{
if(document.getElementById("txt1").value=="")
{
alert('txt1 not null');
}
}
if(document.getElementById("b").style.display=='block')
{
if(document.getElementById("txt2").value=="")
{
alert('txt2 not null');
}
}
}
</script>
</head>
<body>
<form method="post" action="d.php" name="f1">
<input type="button" name="dis1" value="显示div_a" onclick="document.getElementById('a').style.display='block'"/>
<input type="button" name="dis2" value="显示div_b" onclick="document.getElementById('b').style.display='block'"/>
<div id='a' style="display:none">
<input type="text" id="txt1" name="txt1" value="" />
</div>
<div id='b' style="display:none">
<input type="text" id="txt2" name="txt2" value="" />
</div>
<input type="button" name="but" value="提交" onclick="checkValue()"/>
</form>
</body>
</html>