易截截图软件、单文件、免安装、纯绿色、仅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 获取对象的高度和宽度详细说明

scrollHeight: 获取对象的滚动高度。
scrollLeft:设置或获取位于对象左边界和窗口中目前可见内容的最左端之间的距离
scrollTop:设置或获取位于对象最顶端和窗口中可见内容的最顶端之间的距离
scrollWidth:获取对象的滚动宽度
offsetHeight:获取对象相对于版面或由父坐标 offsetParent 属性指定的父坐标的高度
offsetL ......

使用javascript获取文本框,下拉框,单选框的值并且赋值

1.文本框
1.1 <input type="text" name="test" id="test">
通过var t=document.getElementById("test").value把值赋给变量t,
1.2  当然也可以反过来把已知的变量值赋给文本框,例如:
var m = "5";
document.getElementById("test").value= m;
2.下拉列表框
2.1 <select name="sel" id="sel" onchange ......

Javascript 定时器调用传递参数的使用方法(转)

 Javascript 定时器调用传递参数的使用方法
from:txdnet.cn, Date:2008-04-24 08:18:36.0, Hit:317
Tag:0 
Do:收藏到IE Google baidu yahoo QQ书签 mySpace 评论(0) 轉爲繁體 大 中 小
无论是window.setTimeout 还是window.setInterval ......

简单的javascript拖拽实例

简单的javascript拖拽实例----> 本人原创(244796562@qq.com)
<html>
<head>
<title>拖拽测试</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<div id="box" style="position:absolute;top:100px;left:200px;width ......

JavaScript中的document.cookie的使用

我们已经知道,在 document 对象中有一个 cookie 属性。但是 Cookie 又是什么?“某些 Web 站点在您的硬盘上用很小的文本文件存储了一些信息,这些文件就称为 Cookie。”—— MSIE 帮助。一般来说,Cookies 是 CGI 或类似,比 HTML 高级的文件、程序等创建的,但是 javascript 也提供了对 Cookies 的很 ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号