一、JQuery对页面元素自动计算
失去焦点获取每个需要值相加(name法)
$("input[name='formBean.programmeBuildFund']").blur(function(){
var programmeBuildFund = Number($("input[name='formBean.programmeBuildFund']").val());
var programmeBuildOtherFund = Number($("input[name='formBean.programmeBuildOtherFund']").val());
var prepareFund = Number($("input[name='formBean.prepareFund']").val());
//处理丢失精准度
totalAssets = (programmeBuildFund*100+programmeBuildOtherFund*100+prepareFund*100)/100;
$("input[name='formBean.totalAssets']").val(totalAssets);
});
$("input[name='formBean.programmeBuildOtherFund']").blur(function(){
var programmeBuildFund = Number($("input[name='formBean.programmeBuildFund']").val());
var programmeBuildOtherFund = Number($("input[name='formBean.programmeBuildOtherFund']").val());
var prepareFund = Number($("input[name='formBean.prepareFund']").val());
totalAssets = (programmeBuildFund*100+programmeBuildOtherFund*100+prepareFund*100)/100;
$("input[name='formBean.totalAssets']").val(totalAssets);
});
$("input[name='formBean.prepareFund']").blur(function(){
var programmeBuildFund = Number($("input[name='formBean.programmeBuildFund']").val());
var programmeBuildOtherFund = Number($("input[name='formBeanprogrammeBuildOtherFund']").val());
var prepareFund = Number($("input[name='formBean.prepareFund']").val());
totalAssets = (programmeBuildFund*100+programmeBuildOtherFund*100+prepareFund*100)/100;
$("input[name='formBean.totalAssets']").val(totalAssets);
});
处理丢失精准度(化为整数在相加,这里输入框现在2位小数)
失去焦点获取每个需要值相加(class法)
//所有计算input加上class -> add,遍历相加
$(".add").on("blur", function() {
var totalInvestment = 0;
$(".add").each(function() {
totalInvestment += parseFloat($(this).val());
});
$("input[name='digitalInfrastructure.totalInvestment']").attr("value", totalInvestment);
})
绑定回车键事件
//绑定回车键登陆事件
document.onkeydown = function(event) {
var e = event || window.event || arguments.callee.caller.arguments[0];
if (e && e.keyCode == 13) { // enter 键
$("#submitForm").click();
}
};
密码有效性验证
function check_pass(val) {
var value = val;
var value_length = value.length;
var code_length = 0;
//第一个必须条件的验证6-20位之间
if (value_length >= 6 && value_length <= 20) {
//$('#reg .info_pass .q1').html('●').css('color', 'green');
} else {
//$('#reg .info_pass .q1').html('○').css('color', '#666');
}
//第二个必须条件的验证,字母或数字或非空字符,任意一个即可
if (value_length > 0 && !/\s/.test(value)) {
//$('#reg .info_pass .q2').html('●').css('color', 'green');
} else {
//$('#reg .info_pass .q2').html('○').css('color', '#666');
}
//第三个必须条件的验证,大写字母,小写字母,数字,非空字符 任意两种混拼即可
if (/[\d]/.test(value)) {
code_length++;
}
if (/[a-z]/.test(value)) {
code_length++;
}
if (/[A-Z]/.test(value)) {
code_length++;
}
if (/[^\w]/.test(value)) {
code_length++;
}
if (code_length >= 2) {
//$('#reg .info_pass .q3').html('●').css('color', 'green');
} else {
//$('#reg .info_pass .q3').html('○').css('color', '#666');
}
//安全级别
if (value_length >= 10 && code_length >= 3) {
$(".pwdmsg").css('color','#32CD32').text("高 ");
} else if (value_length >= 8 && code_length >= 2) {
$(".pwdmsg").css('color','#ff8a4f').text("中 ");
} else if (value_length >= 1) {
$(".pwdmsg").css('color','#FF6347').text("低 ");
} else {
$(".pwdmsg").text(" ");
}
if (value_length >= 8 && value_length <= 20 && !/\s/.test(value) && code_length >= 2) {
return true;
} else {
return false;
}
}
基础密码校验
//校验是同时含有数字和字母,且长度要在8-16位之间
function isNumbAndLetter(str) {
var reg = /^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{8,16}$/;
return reg.test(str);
}