易截截图软件、单文件、免安装、纯绿色、仅160KB

javascript String.replace函数

    javascript的String类内置函数replace(regexp, newString)函数提供了字符串替换功能,从函数原型上可以看出支持 Regular Exp。此函数功能非常实用,但也有几个地方有点混淆,下面通过实际的例子来说明:
    比如我们现在要针对串
var src="<a href=&quot;http://xx.com/a/20100601/000224.htm&quot; target=&quot;_blank&quot;>xxx</a>"
要替换其中的HTML双引号的转移符 &quot; 为实际的 " , 正常我们就会直接调用 src.replace(/&quot;/g, '"');来达到目的,但是js容易让人迷惑的一点就是,这样做并没有实际改变src的值,实际测试发现返回值才是我们需要的结果,而src本身确不发生变化,所以实际中需要通过如下来完成我们的功能:
     src=src.replace(/&quot;/g, '"');


相关文档:

[翻译]High Performance JavaScript(022)

第七章  Ajax  异步JavaScript和XML
    Ajax is a cornerstone of high-performance JavaScript. It can be used to make a page load faster by delaying the download of large resources. It can prevent page loads altogether by allowing for data to be transferred between the client ......

[翻译]High Performance JavaScript(031)

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 ......

javascript prototype介绍的文章

JavaScript是基于对象的,任何元素都可以看成对象。然而,类型和对象是不同的。本文中,我们除了讨论类型和对象的一些特点之外,更重要的是研究如何写出好的并且利于重用的类型。毕竟,JavaScript这种流行的脚本语言如果能够进行良好的封装,并形成一个庞大的类型库,对于重用是非常有意义的。
网上对于prototype的文章很 ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号