JS 去前后空格大全(IE9亲测)

复制代码 代码如下:


<html>
<head>
<title> IE9 亲测JS各种去空格大全 </title>
</head>
<script>
function clearSpace(inputO){
var valueText=inputO.value;
//去掉前后空格
var text1=valueText.replace( /^\s+/, "" ).replace( /\s+$/, "" );
//去掉所有空格
var text2=valueText.replace(/[ ]/g,"");
//去掉前空格
var text3=valueText.replace( /^\s+/, "" );
//去掉后空格
var text4=valueText.replace( /\s+$/, "" );
alert("=="+text1+"==");
alert("=="+text2+"==");
alert("=="+text3+"==");
alert("=="+text4+"==");
}
</script>
<body>
<input type="text" onblur="clearSpace(this);" />
</body>
</html>


简单实用,IE9亲测,各种去空格!~~

您可能感兴趣的文章:

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wdgysy.html