我使用jcryption加密表单。如果我在表单中使用提交按钮,它工作正常。相反,如果我使用按钮并手动提交表单,我的jcryption方法就不会被调用。
below is my code
<html>
<head>
<script type="text/javascript">
$(document).ready(function() {
$("#login").bind('click', function(){
document.authenticatorform.username.value=$("#username").val();
document.authenticatorform.password.value=$("#password").val();
alert('outer hello');
$("#authenticatorform").jCryption({
getKeysURL:"<%=request.getContextPath()%>/keypairrequest",
beforeEncryption:function() {
alert('inner hello');
document.authenticatorform.submit()
return true; },
encryptionFinished:function(encryptedString, objectLength) {return true;}
});
});
});
</script>
<body>
<form:form method="post" action="login.htm" name="authenticatorform" id="authenticatorform">
<input type="hidden" name="username"/>
<input type="hidden" name="password"/>
</form:form>
<input type="button" id="login"/>
</body>
</html>
在代码中只有外部警报正在打印。
是否可以在提交按钮以外的地方调用jcryption?
任何帮助都将非常感谢!!!!!
答案 0 :(得分:1)
尝试使用 on 点击功能代替 bind
Try this:
$("#login").on('click', function(){
//your codes goes here
}