
- Prototype 教程
- Prototype - 首頁
- Prototype - 簡要概述
- Prototype - 有用的特性
- Prototype - 實用工具方法
- Prototype - Element 物件
- Prototype - 數字處理
- Prototype - 字串處理
- Prototype - 陣列處理
- Prototype - 雜湊處理
- Prototype - 基本物件
- Prototype - 模板
- Prototype - 列舉
- Prototype - 事件處理
- Prototype - 表單管理
- Prototype - JSON 支援
- Prototype - AJAX 支援
- Prototype - Range 表達方式
- Prototype - 間隔執行
- Prototype 有用的資源
- Prototype - 快速指南
- Prototype - 有用的資源
- Prototype - 討論
Prototype - truncate() 方法
此方法把字串截斷為給定長度,並附加一個字尾(表示它只是一個摘錄)。
如果不指定,length 引數預設為 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>
輸出
prototype_string_processing.htm
廣告