- Prototype 教程
- Prototype - 主页
- Prototype - 简要概述
- Prototype - 有用功能
- Prototype - 实用方法
- Prototype - Element 对象
- Prototype - 处理数字
- Prototype - 处理字符串
- Prototype - 处理数组
- Prototype - 处理哈希
- Prototype - 基本对象
- Prototype - 模版化
- Prototype - 枚举
- Prototype - 事件处理
- Prototype - 表单管理
- Prototype - JSON 支持
- Prototype - AJAX 支持
- Prototype - 表达范围
- Prototype - 周期性执行
- Prototype 有用资源
- Prototype - 快速指南
- Prototype - 有用资源
- Prototype - 讨论
Prototype - gsub() 方法
该方法用普通的字符串、函数的返回值或模板字符串替换给定模式的每个出现。该模式可以是字符串或正则表达式。
语法
string.gsub(pattern, replacement);
返回值
返回字符串。
示例
<html>
<head>
<title>Prototype examples</title>
<script type = "text/javascript" src = "/javascript/prototype.js"></script>
<script>
function showResult() {
var mouseEvents = 'click dblclick mousedown';
alert( "mouseEvents :" + mouseEvents.gsub(/\s+/, ', ') );
}
</script>
</head>
<body>
<p>Click the button to see the result.</p>
<br />
<br />
<input type = "button" value = "Result" onclick = "showResult();"/>
</body>
</html>
输出
prototype_string_processing.htm
广告