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

javascript 替换空格

 1.自http://jorkin.reallydo.com/article.asp?id=275
第一次发现JavaScript中replace() 方法如果直接用str.replace("-","!") 只会替换第一个匹配的字符.
而str.replace(/\-/g,"!")则可以全部替换掉匹配的字符(g为全局标志)。
replace()
The replace() method returns the string that results when you replace text matching its first argument
(a regular expression) with the text of the second argument (a string).
If the g (global) flag is not set in the regular expression declaration, this method replaces only the first
occurrence of the pattern. For example,
var s = "Hello. Regexps are fun.";s = s.replace(/\./, "!"); // replace first period with an exclamation pointalert(s);
produces the string “Hello! Regexps are fun.” Including the g flag will cause the interpreter to
perform a global replace, finding and replacing every matching substring. For example,
var s = "Hello. Regexps are fun.";s = s.replace(/\./g, "!"); // replace all periods with exclamation pointsalert(s);
yields this result: “Hello! Regexps are fun!”
所以可以用以下几种方式.:
string.replace(/reallyDo/g, replaceWith);
string.replace(new RegExp(reallyDo, 'g'), replaceWith);
string:字符串表达式包含要替代的子字符串。
reallyDo:被搜索的子字符串。
replaceWith:用于替换的子字符串。
<mce:script type="text/javascript"><!--
String.prototype.replaceAll = function(reallyDo, replaceWith, ignoreCase) {
if (!RegExp.prototype.isPrototypeOf(reallyDo)) {
return this.replace(new RegExp(reallyDo, (ignoreCase ? "gi": "g")), replaceWith);
} else {
return this.replace(reallyDo, replaceWith);
}
}
// --></mce:script>
本文来源于 KinJAVA日志 (http://jorkin.reallydo.com)
原文地址: http://jorkin.reallydo.com/article.asp?id=275

2.自http://yueguangyuan.javaeye.com/blog/31744
方法: string.replace(new RegExp(oldString,"gm"),newString))
gm     g=global, m=multiLine  ,  大致上方法就是这样的,可以实现


相关文档:

JavaScript获取session里对象的值


代码入下:
<script language="JavaScript">
function getMyName(){
   var myName="<%=session.getAttribute("MYNAME")%>";
   alert(myName);
}
</script>
JavaScript存session的值:
 从理论上来说JavaScript在页面,而存session在服务器端..很难完成,但是你可 ......

javascript面向对象编程

封装:通过闭包才算的上是真正意义上的封装
<script type="text/javascript">
  function myInfo(){
    var name ="老鱼",age =27;
    var myInfo = "my name is" + name + "i am" + age  ......

JavaScript运算符详解

       1、javascript具有下列种类的运算符:算术运算符;等同运算符与全同运算符;比较运算符;
  2、目的分类:字符串运算符;逻辑运算符;逐位运算符;赋值运算符;
  3、特殊运算符:条件运算符;typeof运算符;创建对象运算符new;delete运算符;void运算符号;逗号运算符;
  算术运算符: ......

call javascript in firefox


方法一、
NPN_GetURL(m_Instance, "javascript:test()",  NULL);
方法二、
 NPVariant rval;
 NPN_InvokeDefault(m_Npp,  objectDisconnect ,NULL, 0,&rval);
 NPN_ReleaseVariantValue(&rval);
以下是javascript
 <script type="text/javascript"> 
 &nb ......

[转]JAVASCRIPT 中meta的功能

meta是用来在HTML文档中模拟HTTP协议的响应头报文。
meta 标签用于网页的<head>与</head>中,meta 标签的用处很多。
meta 的属性有两种:name和http-equiv。name属性主要用于描述网页,
对应于content(网页内容),以便于搜索引擎机器人查找、分类
(目前几乎所有的搜索引擎都使用网上机器人自动查找m ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号