Prototype-string-truncate
提供:Dev Guides
プロトタイプ-truncate()メソッド
このメソッドは、文字列を指定された長さに切り捨て、接尾辞を追加します(抜粋のみであることを示します)。
指定しない場合、長さパラメータはデフォルトで30になり、接尾辞は「…」になります。
構文
string.truncate([length = 30[, suffix = '...']]) ;
戻り値
切り捨てられた文字列を返します。
例
<html>
<head>
<title>Prototype examples</title>
<script type = "text/javascript" src = "/javascript/prototype.js"></script>
<script>
function showResult() {
var str = 'A random sentence whose length exceeds 30 characters.';
alert("str.truncate() : " + str.truncate() );
alert("str.truncate( 10 ) : " + str.truncate(10) );
alert("str.truncate( 10, '...') : " +
str.truncate(10, '...') );
}
</script>
</head>
<body>
<p>Click the button to see the result.</p>
<br/>
<br/>
<input type = "button" value = "Result" onclick = "showResult();"/>
</body>
</html>