0

$(document).on('输入'.....

我有以下代码..此代码与人工键盘检测一起使用。但是,如果单击“强通过”按钮,这将不起作用。

<form>    
    <input id="pass1" type="text" />
    <input id="pass2" type="text" />
    <a class="button" onclick="strongPass(8)">Strong Pass</a>
</form>

<script>
$(document).on('input change keyup','#pass1, #pass2',function(){
          check_pass_strength_now();
});

function strongPass(){
  .....
  //with a loop generate Strong pass
  //and replace #pass1 #pass2 value
  //But after replace do not catch this $(document).on('input change keyup','#pass1, #pass2'
  .....
}
</script>
4

2 回答 2

0
<form id="profile">
    <input id="pass1" type="text" />
    <input id="pass2" type="text" /> <a class="button">Strong Pass</a>

</form>
<div id="pass-strength-result" class="alert alert-info" style="width:169px">Password line</div>

jQuery

// MY CODE START HERE
var keylist="abcdefghijklmnopqrstuvwxyz123456789"
var temp=''

function generatepass(plength){
       temp=''
for (i=0;i<plength;i++)
temp+=keylist.charAt(Math.floor(Math.random()*keylist.length))
return temp
}

$(document).on('click','.button',function(){ 
    $('#profile #pass1,#profile #pass2').val(generatepass(8));
    check_pass_strength();
});


/*********/



                    function check_pass_strength () {

                        var pass = $('#pass1').val();
                        var pass2 = $('#pass2').val();
                        var user = 'admin';
                        $('#pass-strength-result').removeClass('short bad good strong');
                        if ( ! pass ) {
                            $('#pass-strength-result').html( pwsL10n.empty );
                            return;
                        }

                        var strength = passwordStrength(pass, user, pass2);
                        $('#pass-strength-result').removeClass('good strong danger bad');
                        if ( 2 == strength )
                            $('#pass-strength-result').addClass('bad').html( pwsL10n.bad );
                        else if ( 3 == strength )
                            $('#pass-strength-result').addClass('good').html( pwsL10n.good );
                        else if ( 4 == strength )
                            $('#pass-strength-result').addClass('strong').html( pwsL10n.strong );
                        else if ( 5 == strength )
                             $('#pass-strength-result').addClass('danger').html( pwsL10n.mismatch );
                        else
                            $('#pass-strength-result').addClass('danger').html( pwsL10n.short );

                    }
                    /*$(document).on('input','#pass1, #pass2',function( {check_pass_strength();});*/
                    $('#pass1, #pass2').val('').keyup( check_pass_strength ).change(check_pass_strength);

            pwsL10n = {
                empty: "Password line",
                short: "Very easy",
                bad: "Easy",
                good: "Medium",
                strong: "High",
                mismatch: "Different Password"
            }
            try{convertEntities(pwsL10n);}catch(e){};


//------------------- Another include (Plug-in)------------------

// Password strength meter
function passwordStrength(password1, username, password2) {
    var shortPass = 1, badPass = 2, goodPass = 3, strongPass = 4, mismatch = 5, symbolSize = 0, natLog, score;

    // password 1 != password 2
    if ( (password1 != password2) && password2.length > 0)
        return mismatch

    //password < 4
    if ( password1.length < 4 )
        return shortPass

    //password1 == username
    if ( password1.toLowerCase() == username.toLowerCase() )
        return badPass;

    if ( password1.match(/[0-9]/) )
        symbolSize +=10;
    if ( password1.match(/[a-z]/) )
        symbolSize +=26;
    if ( password1.match(/[A-Z]/) )
        symbolSize +=26;
    if ( password1.match(/[^a-zA-Z0-9]/) )
        symbolSize +=31;

    natLog = Math.log( Math.pow(symbolSize, password1.length) );
    score = natLog / Math.LN2;

    if (score < 40 )
        return badPass

    if (score < 56 )
        return goodPass

    return strongPass;
}

演示:http: //jsfiddle.net/iOnur/rqDdp/

于 2013-09-21T08:01:15.937 回答
-1

尝试在 strongPass 函数的末尾添加它(循环外)

function strongPass(){
    .....
    //with a loop generate Strong pass
    //and replace #pass1 #pass2 value
    //But after replace do not catch this $(document).on('input change keyup','#pass1, #pass2'
    .....

    $( "#pass1" ).trigger('keyup');
    $( "#pass2" ).trigger('keyup');
}
于 2013-09-16T16:20:39.520 回答