window.I = {} var basic = getpath(); var modelview = function() { var self = this; self.opwd = ko.observable(); self.npwd = ko.observable(); self.rnpwd = ko.observable(); } jQuery(document).ready( function($) { var flag = true; var md = window.md = new modelview(); ko.applyBindings(md); var fm1 = $('#fm1'); fm1.validate({ rules : { opwd : "required", npwd : { required : true, maxlength : 16, minlength : 6 }, rnpwd : { required : true, equalTo : '#npwd', maxlength : 16, minlength : 6 } }, messages : { opwd : "请输入旧密码", npwd : { required : "请输入新密码", maxlength : '最大长度不能超过16', minlength : '最小长度不能小于6' }, rnpwd : { required : "请输入新密码确认", maxlength : '最大长度不能超过16', minlength : '最小长度不能小于6', equalTo : '#新密码前后输入不一致,请重新输入' } } }); $("#npwd").change(function() { var opwd = $("#opwd").val(); var npwd = $("#npwd").val(); if (opwd == npwd) { flag=false; alert("新密码和旧密码不能一致,请重新输入!"); } }) $('#tjbtn').click( function(event) { /* Act on the event */ if (!fm1.valid()||flag==false) return; var obj = {}; obj.oldpwd = md.opwd(); obj.newpwd = md.npwd(); obj.rnpwd = md.rnpwd(); jQuery.post(basic + '/system/savePwd.htm', obj, function(data, textStatus, xhr) { // optional stuff to do after success if (data == null) { // showErrmsg('系统没有响应!'); swal({title:'',text:'系统没有响应!',type:'error',confirmButtonText:'确定'}); return; } if (data.code == 0) { showErrmsg('密码修改成功!'); return; } else { swal({title:'',text:'密码失败,请重新修改!',type:'error',confirmButtonText:'确定'}); // showErrmsg('密码失败,请重新修改!'); return; } }, 'json'); }); });