2023年6月21日发(作者:)

在表单提交前进⾏验证的⼏种⽅式1在button的submit事件时判断

("#form").bind("submit",function(){ var txt_firstname = $.trim($("#firstname").attr("value")); var isSuccess = 1;//默认验证通过 if(txt_ == 0){

$("#firstnameLabel").text("firstname不能为空!")

$("#firstnameLabel").css({"color":"red"});

isSuccess = 0; //验证不通过,修改isSuccess }

if(isSuccess == 0){ return false;//最后未通过,不提交

}})2 在form的onsubmit判断

function check(){

var txt_firstname = $.trim($("#firstname").attr("value"));

var isSuccess = 1;

if(txt_ == 0)

{

$("#firstnameLabel").text("firstname不能为空!")

$("#firstnameLabel").css({"color":"red"});

isSuccess = 0;

}

if(isSuccess == 0){

return false;

}

return true;

}

注意:onsubmit=“return false”为不执⾏提交;onsubmit=“return true”或onsubmit=“return ”都执⾏提交。3 去掉submit类型button,直接⽤普通button.

function checktosubmit(){

var txt_firstname = $.trim($("#firstname").attr("value"));

var isSuccess = 1;

if(txt_ == 0)

{

$("#firstnameLabel").text("firstname不能为空!")

$("#firstnameLabel").css({"color":"red"});

isSuccess = 0;

}

if(isSuccess == 1)

{

();

}

} 原⽂链接:/qian_f/article/details/9631691

2023年6月21日发(作者:)

在表单提交前进⾏验证的⼏种⽅式1在button的submit事件时判断

("#form").bind("submit",function(){ var txt_firstname = $.trim($("#firstname").attr("value")); var isSuccess = 1;//默认验证通过 if(txt_ == 0){

$("#firstnameLabel").text("firstname不能为空!")

$("#firstnameLabel").css({"color":"red"});

isSuccess = 0; //验证不通过,修改isSuccess }

if(isSuccess == 0){ return false;//最后未通过,不提交

}})2 在form的onsubmit判断function check(){

var txt_firstname = $.trim($("#firstname").attr("value"));

var isSuccess = 1;

if(txt_ == 0)

{

$("#firstnameLabel").text("firstname不能为空!")

$("#firstnameLabel").css({"color":"red"});

isSuccess = 0;

}

if(isSuccess == 0){

return false;

}

return true;

}

注意:onsubmit=“return false”为不执⾏提交;onsubmit=“return true”或onsubmit=“return ”都执⾏提交。3 去掉submit类型button,直接⽤普通button.

function checktosubmit(){

var txt_firstname = $.trim($("#firstname").attr("value"));

var isSuccess = 1;

if(txt_ == 0)

{

$("#firstnameLabel").text("firstname不能为空!")

$("#firstnameLabel").css({"color":"red"});

isSuccess = 0;

}

if(isSuccess == 1)

{

();

}

} 原⽂链接:/qian_f/article/details/9631691