[javascript]代码库
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>JS中的String对象</title>
</head>
<body>
<script type="text/javascript">
/*
演示JS中的String对象的常用方法
*/
document.write("itcast".big() + "<br />");
document.write("itcast".blink() + "<br />");
document.write("itcast".bold() + "<br />");
document.write("itcast".fontcolor('red') + "<br />");
document.write("itcast".fontsize(18) + "<br />");
/*
需求:定义功能,去除字符串两端的空格
var s = " sh itcast "; "sh itcas"
*/
var s = " sh itcast ";
var start = 0;
var end = s.length-1;
while( s.charAt(start) == ' ' ){
start++;
}
//上面的循环结束,start在字符s的位置
while( s.charAt(end) == ' ' ){
end--;
}
//上面的循环结束,end在字符t的位置
document.write("----"+ s + "-----<br />");
document.write("----"+s.substring(start, end+1) + "----<br />");
</script>
</body>
</html>