当前位置: 代码迷 >> Web前端 >> 【转】除开输入框内容的所有空格
  详细解决方案

【转】除开输入框内容的所有空格

热度:87   发布时间:2012-10-19 16:53:37.0
【转】去除输入框内容的所有空格
原文地址 http://www.devcurry.com/2010/11/remove-all-white-space-using-javascript.html

<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>Remove Whitespaces using JavaScript by DevCurry.com</title>
    <script type="text/javascript">
        function removeWhitespaces() {
            var txtbox = document.getElementById('txtOne');
            txtbox.value = txtbox.value.replace(/\s/g, "");
        }
    </script>
</head>
<body>
    <input id="txtOne" type="text" /><br />
    <input id="btnRemoveWs" type="submit"
    value="Remove Whitespaces" onclick="removeWhitespaces()" />
</body>
</html>


The "g" stands for "global" which replaces all white space matches (front, trailing and in between)
  相关解决方案