我有一個包含密碼錶的登錄表單的項目。我跟着a tutorial from cssdeck,然後試着將代碼複製粘貼到JSFiddle以查看結果。它適用於演示版,但不適用於my JSFiddle。問題是密碼錶不起作用。我已經閱讀了JavaScript,看不出有什麼問題。
任何建議都會很好。爲什麼完全相同的代碼不能在小提琴中使用?Javascript未運行或正在運行?
$(function(){
var pass1 = $('#password1'),
pass2 = $('#password2'),
email = $('#email'),
form = $('#main form'),
arrow = $('#main .arrow');
// Empty the fields on load
$('#main .row input').val('');
// Handle form submissions
form.on('submit', function(e){
// Is everything entered correctly?
if ($('#main .row.success').length == $('#main .row').length) {
// Yes!
alert("Thank you for trying out this demo!");
e.preventDefault();
// Remove this to allow actual submission
} else {
// No. Prevent form submission
e.preventDefault();
}
});
// Validate the email field
email.on('blur', function(){
// Very simple validation
if (!/^\[email protected]\S+\.\S+$/.test(email.val())) {
email.parent().addClass('error').removeClass('success');
} else {
email.parent().removeClass('error').addClass('success');
}
});
// Use the complexify plugin on the first password field
pass1.complexify({minimumChars: 6, strengthScaleFactor: 0.7},
function(valid, complexity){
if (valid) {
pass2.removeAttr('disabled');
pass1.parent().removeClass('error').addClass('success');
} else {
pass2.attr('disabled','true');
pass1.parent().removeClass('success').addClass('error');
}
var calculated = (complexity/100) * 268 - 134;
var prop = 'rotate(' + (calculated) + 'deg)';
// Rotate the arrow
arrow.css({
'-moz-transform': prop,
'-webkit-transform': prop,
'-o-transform': prop,
'-ms-transform': prop,
'transform': prop
});
}
);
// Validate the second password field
pass2.on('keydown input', function(){
// Make sure its value equals the first's
if (pass2.val() == pass1.val()) {
pass2.parent().removeClass('error').addClass('success');
} else {
pass2.parent().removeClass('success').addClass('error');
}
});
});
還包括jquery.complexify插件。
密碼錶適用於我的小提琴。你看到控制檯中有任何錯誤嗎? – TheDude
您是否在頁面中正確包含了[jQuery](https://jquery.com/download/)? –
它似乎在原始文章中適用於我,但不適用於我的項目。這裏是一個小提琴 - https://jsfiddle.net/9hkdL51p/ –