<div class="codetitle"> <span><a style="CURSOR: pointer" data="87720" class="copybut" id="copybut87720" onclick="doCopy('code87720')"><u>复制代码</u></a></span> 代码如下:</div> <div class="codebody" id="code87720"> <br> <br> <br><title> IE9 亲测JS各种去空格大全 </title> <br> <br><script> <BR>function clearSpace(inputO){ <BR>var valueText=inputO.value; <BR>//去掉前后空格 <BR>var text1=valueText.replace( /^\s+/, "" ).replace( /\s+$/, "" ); <BR>//去掉所有空格 <BR>var text2=valueText.replace(/[ ]/g,""); <BR>//去掉前空格 <BR>var text3=valueText.replace( /^\s+/, "" ); <BR>//去掉后空格 <BR>var text4=valueText.replace( /\s+$/, "" ); <BR>alert("=="+text1+"=="); <BR>alert("=="+text2+"=="); <BR>alert("=="+text3+"=="); <BR>alert("=="+text4+"=="); <BR>} <BR></script> <br> <br><input type="text" id="appNo" onblur="clearSpace(this);"> <br> <br> <br> </div> <br>简单实用,IE9亲测,各种去空格!~~