split:
split() 方法用于把一个字符串分割成字符串数组。<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>I do not know</title>
<script type="text/javascript">
function test1(){
var abc="1,2,3,4,5";
var bc=abc.split("3");
alert(bc[0]);
alert(bc[1]);
}
</script>
</head>
<body>
<input type="button" οnclick="test1()" />
</body>
</html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>I do not know</title>
<script type="text/javascript">
function test1(){
var abc="1,2,3,4,5";
var bc=abc.split("3");
alert(bc[0]);
alert(bc[1]);
}
</script>
</head>
<body>
<input type="button" οnclick="test1()" />
</body>
</html>
显示结果1,2,和,4,5
注释:如果把空字符串 ("") 用作 separator,那么 stringObject 中的每个字符之间都会被分割。
匿名函数(方法):
function next(name,sex){
this.name=name;
this.sex=sex;
this.change=function change(sex){
this.sex=sex;
}
}
var aa=new next("zengrui","nv");
aa.change("nan");
alert(aa.sex);
for in 循环:
function test1(){
var abc="1234";
var bc=abc.split("");
for(x in bc){
alert(bc[x]);
}
}
注:x为循环参数,bc为要遍历的数组对象
getElementsByTagName():通过标签名来获取到一个对象
function test1(){
var x=document.getElementsByTagName("p")
alert(x);
}
获取标签中的值:
var hh=document.getElementById("si");
hh.options[hh.selectedIndex].text=sc_s[0];