原型 - interpolate() 方法
此方法將字串視為模板並用物件屬性填充它。
語法
string.inspect([useDoubleQuotes = false]);
返回值
返回插值字串。
示例
<html>
<head>
<title>Prototype examples</title>
<script type = "text/javascript" src = "/javascript/prototype.js"></script>
<script>
function showResult() {
var str = "#{animals} on a #{transport}";
alert(str.interpolate({animals:"Cow",transport:"Train"}));
}
</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
廣告