开发者

Masked input: I can't get the simplest completion to work

开发者 https://www.devze.com 2022-12-28 18:11 出处:网络
Trying to use Josh Bush\'s masked input plugin. I want to shift focus and do other things once the person puts their cell phone in. I mask to a phone shape. When I hit the last letter, I want it to t

Trying to use Josh Bush's masked input plugin.

I want to shift focus and do other things once the person puts their cell phone in. I mask to a phone shape. When I hit the last letter, I want it to trigger a JavaScript function. Right now that function just alerts "hi".

I even copied the demo right off Josh Bush's page: http://digitalbush.com/projects/masked-input-plugin/ the third one for triggering something to complete. Copying it verbatim and it still doesn't work?

Am I crazy?开发者_StackOverflow中文版 Can anyone get this to work.

function jump(){
    alert('hi');
}

$(document).ready(function(){
    $("#cellphone").focus();
    jQuery(function($){
        $("#product").mask("(999) 999-9999",{completed:function(){jump();}});      
    });
 });     


I just tried this plugin and it works great, at it seems that the complete function is somewhat broken, I'm using the latest 1.2.2. If you download the uncompressed and replaced line 169

changed this on line 169:

if (settings.completed && next == len)

to

if (settings.completed && next == len+1)

also you're targeting the wrong id

$(document).ready(function(){
    $("#cellphone").focus();
    jQuery(function($){
        $("#product").mask("(999) 999-9999",{completed:function(){jump();}});      
    });
 }); 

first you're checking #cellphone right? then #product should suppose be #cellphone,

please allow me to edit your code a bit:

$(document).ready(function(){
    function jump(){
    alert('hi');
    }                                                    
    $("#cellphone").focus();
    $("#cellphone").mask("(999) 999-9999",{completed:function(){jump();}});      
}); 
0

精彩评论

暂无评论...
验证码 换一张
取 消