t0ze Posted December 18, 2012 Report Share Posted December 18, 2012 Boa tarde pessoal, É com certeza burrice minha, mas não sei simplesmente o que fazer: http://jsfiddle.net/SnakeEyes/eu7P9/3/ Não consigo criar um ficheiro .html com esse exemplo. <script src="http://code.jquery.com/jquery-latest.min.js" type="text/javascript"></script> <script type="text/javascript"> $('.numbersOnly').keyup(function () { if(($(this).val().split(".")[0]).indexOf("00")>-1){ $(this).val($(this).val().replace("00","0")); } else { $(this).val($(this).val().replace(/[^0-9\.]/g,'')); } }); </script> <input type="text" id="numbersOnly" value=""/> Alguem pode dar uma dica? Cumps Link to comment Share on other sites More sharing options...
yoda Posted December 18, 2012 Report Share Posted December 18, 2012 http://docs.jquery.com/Tutorials before you post, what have you tried? - http://filipematias.info sense, purpose, direction Link to comment Share on other sites More sharing options...
t0ze Posted December 18, 2012 Author Report Share Posted December 18, 2012 Está certo. "vai aos tutoriais e desminerda-te" ... (é que nem sei o que pesquisar, pesquisei por decimal validator, fiz um teste, e apareceu-me a http://docs.jquery.com/Tutorials metita no iframe do exemplo q lá está). Link to comment Share on other sites More sharing options...
KiNgPiTo Posted December 18, 2012 Report Share Posted December 18, 2012 1º O Selector está a procurar pela class. Em vez de $('.numbersOnly') usa $('#numbersOnly') 2º Cria o corpo do html (head, body) 3º Insere os scripts no head (cria o $(document).ready() e mete a tua função lá... O tutorial do yoda ajuda-te com isto... 1 Report Link to comment Share on other sites More sharing options...
t0ze Posted December 18, 2012 Author Report Share Posted December 18, 2012 <html> <head> <title></title> <script src="http://code.jquery.com/jquery-1.8.3.min.js" type="text/javascript"></script> <script type="text/javascript"> $(document).ready(function() { $('.numbersOnly').keyup(function (e) { if(($(this).val().split(".")[0]).indexOf("00")>-1){ $(this).val($(this).val().replace("00","0")); } else { $(this).val($(this).val().replace(/[^0-9\.]/g,'')); } if($(this).val().split(".")[2] != null || ($(this).val().split(".")[2]).length ){ $(this).val($(this).val().substring(0, $(this).val().lastIndexOf("."))); } }); }); </script> </head> <body> <input type="text" class="numbersOnly" value="" /> </body> </html> Obrigado KiNgPiTo e yoda. KiNgPiTo se não fosse o teu post a encaminhar-me era difícil, só com o tutorial que o yoda enviou (e que ajudou e q foi mto útil na definição da função) Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now