简体   繁体   中英

Post data from input

Hope that i can get an answer...i'm trying to post an input value in this format. I want to be able to get the entered text, not the character that replaces the text. Input type="password" is not a solution.

 var text = ""; $('input[type="text"]').keyup(function(e){ if(e.which === 8){ text = text.substr(0, text.length - 1); } var data = $(this).val(); $(this).val( data.replace(/[&\\/\\\\#,+()$~%.'":*@!?^<>{}\\w\\s]/g, '●')); }); $('input[type="text"]').keypress(function(e){ text += String.fromCharCode(e.keyCode); console.log(text); }); 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> <input name="newname" type="text" id="txt1" autocomplete="off"> 

How about Changing keypress to keydown ? since keydown event always fire before keyup

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM