修剪功能无法正常工作
<input class="input"></input>
<div class="button">CLICK</div>
$(".button").click(function() {
var name = $( ".input" ).val();
name = $.trim(name);
console.log("TRIM " + name);
});
Run Code Online (Sandbox Code Playgroud)
修剪从字符串的开头和结尾删除空格.
如果要删除连续的空格'string string',请使用以下内容:
$.trim(name.replace(/\s+/g, ' '));
Run Code Online (Sandbox Code Playgroud)
$(".button").on('click', function() {
var name = $.trim($('input').val().replace(/\s+/g, ' '));
console.log("TRIM " + name);
});Run Code Online (Sandbox Code Playgroud)
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input class="input"></input>
<div class="button">CLICK</div>Run Code Online (Sandbox Code Playgroud)