javascript trim方法
在javascript中的string对象没有trim方法,所以trim功能需要自己实现:
代码如下:
Java代码
﹤scriptlanguage=”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﹥
﹤scriptlanguage=”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﹥
使用如下
Java代码
﹤scripttype=”text/javascript”﹥
alert(document.getElementById(’abc’).value.trim());
alert(document.getElementById(’abc’).value.ltrim());
alert(document.getElementById(’abc’).value.rtrim());
﹤/script﹥
相关文档:
页面提交数据一般有两种方法:get,post。post就是所谓的form提交,使用视图;get是通过url提交。
Get方法一般用后台代码(如asp,asp.net)获得参数,代码很简单:Request.QueryString["id"];即可获取。
有些时候需要直接在前台获取url参数,要用到javascript,js没有直接获取url参数的方法,那么,我们如何通过js ......
第九章
Building and Deploying High-Performance JavaScript Applications
创建并部署高性能JavaScript应用程序
According to a 2007 study by Yahoo!'s Exceptional Performance team, 40%–60% of Yahoo!'s users have an empty cache experience, and about 20% of all page views are done ......
Firebug
Firefox is a popular browser with developers, partially due to the Firebug addon (available at http://www.getfirebug.com/), which was developed initially by Joe Hewitt and is now maintained by the Mozilla Foundation. This tool has increased the productivity of web develop ......
Fiddler
Fiddler is an HTTP debugging proxy that examines the assets coming over the wire and helps identify any loading bottlenecks. Created by Eric Lawrence, this is a general purpose network analysis tool for Windows that provides detailed reports on any browser or web request. ......
JavaScript是基于对象的,任何元素都可以看成对象。然而,类型和对象是不同的。本文中,我们除了讨论类型和对象的一些特点之外,更重要的是研究如何写出好的并且利于重用的类型。毕竟,JavaScript这种流行的脚本语言如果能够进行良好的封装,并形成一个庞大的类型库,对于重用是非常有意义的。
网上对于prototype的文章很 ......