日期:2014-05-16  浏览次数:20431 次

初学者问题:怎么判断form有内容被修改了
怎么判断form里内容是否被修改啊?急在线等

------解决方案--------------------
建立与form内的各表单一一匹配的隐藏域,如:

原来的form内容:
<form name= "form1 ">
<input type= "text " name= "txtUser1 " value= "myname ">
</form>
修改过后的form内容
<form name= "form1 ">
<input type= "text " name= "txtUser1 " value= "myname ">
<input type= "hidden " name= "hidUser1 " value= "myname "> --增加匹配项
</form>

这样只要通过js判断text的内容是否与hidden内容是否一样就可以了

------解决方案--------------------
<script>
function checkForm()
{
frm = document.f;
for(c=0;c <frm.length;c++)
{
o = frm.elements[c];
if(o.value!=o.defaultValue) alert( "已修改 ");
}
}
</script>
<form name= "f " onsubmit= "checkForm() ">
<input name= "a " value= "1 ">
<input name= "b " value= "2 ">
<input type= "submit " value= "提交 ">
</form>
------解决方案--------------------
建立与form内的各表单一一匹配的隐藏域,如:

原来的form内容:
<form name= "form1 ">
<input type= "text " name= "txtUser1 " value= "myname ">
</form>
修改过后的form内容
<form name= "form1 ">
<input type= "text " name= "txtUser1 " value= "myname ">
<input type= "hidden " name= "hidUser1 " value= "myname "> --增加匹配项
</form>

这样只要通过js判断text的内容是否与hidden内容是否一样就可以了
========================================================================
此法可行,但可以更简单些,更合理些,这样实现的问题在于,再post表单的时候,要发双倍的数据.
修改过后的form内容
<form name= "form1 ">
<input type= "text " name= "txtUser1 " orivalue= "myname " value= "myname ">
</form>
只要在提交时判断if(txtUser1.orivalue != txtUser1.value) alert( "changed ");