一个js去掉空格的例子


<html>
<head>
<title>
test
</title>
</head>
<body>
<input type="text" name="mytxt" value=" 12345678 " />
 
<input type="button" name="cmd1" onclick="mytxt2.value=mytxt.value.trim()" value="去两边的空格"/>
<input type="text" name="mytxt2"/>
 
<input type="button" name="cmd1" onclick="mytxt3.value=mytxt.value.ltrim()" value="去左边的空格"/>
<input type="text" name="mytxt3"/>
 
<input type="button" name="cmd1" onclick="mytxt4.value=mytxt.value.rtrim()" value="去右边的空格"/>
<input type="text" name="mytxt4"/>
 
<script language="javascript">
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,"");
}
</script>
</body>
</html>

 

<!-- button 变灰色 -->

 

<html>  
  <head>  
  <title>code   by   meixx</title>  
  </head>  
  <body>  
  <input   type="button"   onclick="this.disabled=true"   value="Click   Me">  
  </body>  
  </html>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值