日期:2014-05-16 浏览次数:20467 次
<form name="form">
<input name="n" value="2">
<input name="submit" type="submit" value="提交">
<input type="image" border="0" name="submit" src="AnNiu.png" alt="提交" onClick="Create()">
</form>
<script>
if(document.all){//ie
document.form.submit.attachEvent("onclick",checkform_success);
}else{//ff
document.form.submit.addEventListener("click",checkform_success,false);
};
function checkform_success(e){
e=e||window.event;
if(document.form.n.value>1){
alert("禁止提交!");
if(document.all) e.returnValue=false;//ie,window.event.returnValue=false阻止元素默认行为
else e.preventDefault();//ff,event.preventDefault阻止元素默认行为
}
}
function Create(){
document.form.n.value = "提交成功";
};
</script>
<form name="form" action="?action=ok">
<input name="n" value="2">
<input type="image" name="submit" src="AnNiu.png" value="提交" onClick="return Create()">
</form>
<script>
function Create(e){
var n=parseFloat(document.getElementsByName("n")[0].value);
if(n>1){
alert("禁止提交!");
return false;
}else{
alert("提交成功!");
return false;
}
}
</script>