<script type = "text/javascript">
document.write("substr返回字符串的一個子串,傳入參數是<font color = 'red' size = '3'>起始位置和長度</font>");
var s, ss; // 聲明變量。
var s = "the rain in spain falls mainly in the plain.";
ss = s.substr(12, 5); // 獲取子字符串。
alert(ss);
//return(ss); // 返回 "spain"。
document.write(" <br>");
document.write("substring 返回字符串的一個子串,傳入參數是<font color = 'red' size = '3'> 起始位置和結束位置</font>");
var ss; // 聲明變量。
var s = "the rain in spain falls mainly in the plain..";
ss1 = s.substring(12, 17); // 取子字符串。
//return(ss); // 返回子字符串。
alert(ss1);
</script>