t0ze Posted December 18, 2012 at 06:18 PM Report #487726 Posted December 18, 2012 at 06:18 PM 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
yoda Posted December 18, 2012 at 06:22 PM Report #487727 Posted December 18, 2012 at 06:22 PM http://docs.jquery.com/Tutorials before you post, what have you tried? - http://filipematias.info sense, purpose, direction
t0ze Posted December 18, 2012 at 06:38 PM Author Report #487730 Posted December 18, 2012 at 06:38 PM 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á).
KiNgPiTo Posted December 18, 2012 at 06:47 PM Report #487732 Posted December 18, 2012 at 06:47 PM 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
t0ze Posted December 18, 2012 at 10:09 PM Author Report #487757 Posted December 18, 2012 at 10:09 PM <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)
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