JS去空格
<script>
String.prototype.Trim = function()
{
return this.replace(/(^\s*)|(\s*$)/g, "");
}
String.prototype.LTrim = function()
{
return this.replace(/(^\s*)/g, "");
}
String.prototype.RTrim = function()
{
return this.replace(/(\s*$)/g, "");
}
function StringTrim()
{
document.all.txt_Res.value=document.all.txt_Ori.value.Trim();
}
function StringLTrim()
{
document.all.txt_Res.value=document.all.txt_Ori.value.LTrim();
}
function StringRTrim()
{
document.all.txt_Res.value=document.all.txt_Ori.value.RTrim();
}
</script>
<input type=text id="txt_Ori">
<br />
<input value="去前后空格" type="button" onclick="StringTrim()">
<input value="去前面空格" type="button" onclick="StringLTrim()">
<input value="去后面空格" type="button" onclick="StringRTrim()">
<br />
<input type="text" id="txt_Res">