1
:打印
document.writeln
所写
HTML
内容
<html>
<head>
</head>
<body>
<script laguage="javascript">
document.writeln("" + "<INPUT type=/"button/" " +
"value=/"aaa/" "><br>");
document.writeln("The End")
function window.onload(){alert(document.body.innerHTML);}
//
利用
JS
系统函数
window.onload()
和属性
document.body.innerHTML
打印
body
中的语句
//JS
中注释用
//
表示
ASP
中用
<!-- -->
表示
VBS
中用
’
表示
alert(document.body.innerHTML);
//
或者直接写
alert()
方法
</script>
</body>
</html>
2
:
String.IndexOf(
“
SubString
”
)
的使用
1)
返回起始位置从0开始的子字符串的位置
2)
如果存在相应子串则方法返回相应的位置号 否则返回-1
3)
var the_email =
prompt("What's your email address?", "");
// prompt
弹出对话框
var the_at_is_at =
the_email.indexOf("@");
//
判断是否存在
”
@
”
字符
if (the_at_is_at == -1)
{
alert("You loser, email addresses must have @ signs in them.");
}
3
:
String.CharAt(Int)
的使用
1)
找出起始位置是0的特定位置的字符
2)
注意返回值是字符串而不是单个字符
3)
字符串的长度是String.length作为属性使用
4)
注意不要越界访问 会报错
4
:
String.SubString(from,to)
的使用
1)
返回特定位置区间的子字符串
2)
from从0开始,to的最大值为String.length即所取字符的下一个位置
3)
to-from=返回的字符串的长度
4)
常常与IndexOf()连用 用以抽出特定位置特定长度的字符串
Example:
Var str = "VERNE".SubString(0,5)
--> str = "VERNE" (5-0=5)
Var str2 = "VERNE".SubString(1,3)
--> str2 = "ER" (3-1=2)