---
title: "【转】去除输入框内容的所有空格"
author: "lost_alien"
date: "2011-06-14T09:48:08Z"
tags: []
categories: ["Web前端"]
slug: "untitled"
draft: false
lastmod: "2011-06-14T09:48:08Z"
id: 1085931
url: "https://lost-alien.iteye.com/blog/1085931"
---

原文地址 http://www.devcurry.com/2010/11/remove-all-white-space-using-javascript.html


```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)