demo小样
1.去除字符串中的空格
1 <div class="show-demo"> 2 <input class="input" /> 3 <pre class="pre"></pre> 4 <button class="button">√</button> 5 </div>
1 $('.input').keydown(function () { 2 var v = $('.input').val(); 3 console.log(v); 4 //TODO: trim 5 v = v.replace(/\s/g, ''); 6 $('.pre').text(v); 7 })