javascript - Jquery 验证引擎 onclick

标签 javascript jquery validation

我有这个 jquery 插件 Jquery ValidationEngine,它是由此触发的:

    <script>
        jQuery(document).ready(function(){
            // binds form submission and fields to the validation engine
            jQuery("#editar").validationEngine('attach');
        });
</script>

它工作正常,但在提交按钮上我有这个:

<input type="submit" value="SUBMIT" onclick="formhash(this.form, this.form.password);"  id="BotaoEntrar"/></td>

onclick 通过 JavaScript 文件发送密码(THIS):

    function formhash(form, password) {
   // Create a new element input, this will be out hashed password field.
   var p = document.getElementById("p");
   // Add the new element to our form.
   form.appendChild(p);
   p.name = "p";
   p.type = "hidden"
   p.value = hex_sha512(password.value);
   // Make sure the plaintext password doesn't get sent.
   password.value = "";
   // Finally submit the form.
   form.submit();
}

所以这里的这个东西“剪切”了验证jquery(如果我删除onclick它工作正常,但是加密的密码不起作用)但我希望这两件事一起工作..

类似于“如果验证正确-> formhash....否则回显“错误验证””,但我对 jquery 和 javascript 不太了解。..有可能让这两件事一起工作吗?

这里是 jquery 验证的 API:http://posabsolute.github.io/jQuery-Validation-Engine

最佳答案

您可以使用 jquery 验证引擎 和自定义验证来验证您的表单

jQuery(document).ready(function(){

 jQuery("#editar").validationEngine();
 });


function formhash(form, password) {

if(jQuery("#editar").validationEngine('validate')){
//    first validates with jquery  validationEngine if retuns true then your validation takes place
// Create a new element input, this will be out hashed password field.
var p = document.getElementById("p");
// Add the new element to our form.
form.appendChild(p);
p.name = "p";
p.type = "hidden"
p.value = hex_sha512(password.value);
// Make sure the plaintext password doesn't get sent.
password.value = "";
// Finally submit the form.
 form.submit();


 }
}

关于javascript - Jquery 验证引擎 onclick,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17086804/

相关文章:

javascript - 如何通过 javascript 或 ionic 与 ADFS 3.0 对话?

javascript - getJSON 正在添加之前的 URL。 jQuery

javascript - 基本 JQuery slider : Want to move slide number on top of images

javascript - 在 Jquery 中查找字母数字字符串数组中的最大数字

c# - 验证美国的电话号码是否存在

javascript - 如何在 angularjs 中获取当前 Controller $scope 内部指令函数?

javascript - 将 SQL 查询 + JSON 文件生成移至服务中? wcf? mvc?

javascript - 使用 jQuery XML 解析选定的元素

javascript - html 表格的 slider 功能

javascript - 正则表达式无法验证 28 到 31 之间的日期