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>单击按钮查看结果。</p>
<br />
<br />
<input type = "button" value = "Result" onclick = "showResult();"/>
</body>
</html>
输出
prototype_string_processing.html

