JS验证页面的值有没有修改过...
HTML调用 :
[code]
<script> isModified(document.forms[0].name) </script>
<BODY οnlοad="initPage()">
[/code]
Java验证form的值是否被修改过....
function initPage()
{
for(i=0;i<document.all.tags("select").length;i++)
{
var select = document.all.tags("select").item(i);
if(select.defaultValue == undefined)
select.defaultValue = select.options[select.selectedIndex].value;
}
}
function isModified(objID)
{
isChange = false;
if(document.getElementById(objID) == undefined || document.getElementById(objID) == null)
{
return false;
}
var clInput = document.getElementById(objID).all.tags("input");
var clArea = document.getElementById(objID).all.tags("textarea");
var clSelect= document.getElementById(objID).all.tags("select");
for (i=0;i<clInput.length;i++)
{
if (isChange == true) {
break;
}
switch (clInput.item(i).type)
{
case "text" :
if (clInput.item(i).value != clInput.item(i).defaultValue)
{
isChange = true;
break;
}
case "radio" :
if (clInput.item(i).checked != clInput.item(i).defaultChecked)
{
isChange = true;
break;
}
case "checkbox" :
if (clInput.item(i).checked != clInput.item(i).defaultChecked)
{
isChange = true;
break;
}
}
}
for (i=0;i<clArea.length;i++)
{
if (isChange ==true) {
break;
}
if (clArea.item(i).value != clArea.item(i).defaultValue)
{
isChange = true;
break;
}
}
for (i=0;i<clSelect.length;i++)
{
if (isChange ==true) {
break;
}
if (clSelect[i].defaultValue != clSelect[i].options[clSelect[i].selectedIndex].value)
{
isChange = true;
break;
}
}
return isChange;
}
HTML调用 :
[code]
<script> isModified(document.forms[0].name) </script>
<BODY οnlοad="initPage()">
[/code]
Java验证form的值是否被修改过....
public boolean isChange(Form preForm, Form curForm) {
Class form = Form.class;
Method[] method = form.getMethods();
String pre;
String cur;
for(int i=0; i<method.length; i++)
{
String n = method[i].getName();
if (n != null && n.length() >3 && n.substring(0,3).equals("get")
&& !n.equals("getClass") && !n.equals("getTimestamp")
//不需要比较的方法最加...
){
try {
if(preForm != null && curForm != null) {
pre = (String)method[i].invoke(preForm, new Object[0]);
cur = (String)method[i].invoke(curForm, new Object[0]);
if(isNotBlank(pre) && isNotBlank(cur)) {
if (!pre.equals(cur)) {
return true;
}
}
else if((isBlank(pre) && isNotBlank(cur)) || (isNotBlank(pre) && isBlank(cur))){
return true;
}
}
} catch(Exception e) {
e.printStackTrace();
}
}
}
return false;
}
public boolean isBlank(String target) {
if (target == null || target.equals("")) {
return true;
}
return false;
}
public boolean isNotBlank(String target) {
//target = trim(target);
if (target == null || target.equals("")) {
return false;
}
return true;
}