$('#submit').click(function () { //去除所有空格 String.prototype.NoSpace = function () { return this.replace(/s+/g, ""); }; var user = $('#user').val().NoSpace(); var pwd = $('#pwd').val().NoSpace(); if (user == "" || pwd == "") { return; }else { alert(user + ',' + pwd); } });