ITeye博客

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

lost_alien · 2011-06-14 09:48 · javascript · Web前端 · Markdown

原文地址 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)

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。