js数组中indesOf方法的使用

<html>
<head>
	<title>数组的操作</title>
	<script type="text/javascript">
	


	function B(){
		var names=["zhangsan","lisi","wangwu"];
		
		var name=document.getElementById("name").value;
		var position = names.indexOf(name);
		alert(position);
		if (position >=0) {
			alert("find"+name+"at position"+position);
		}else {
			alert("not find"+name);
		}



	}

	</script>
</head>
<body>
<input type="text" name="name" id="name">
<input type="button" value="dian" onclick="B();">

</body>
</html>

  

posted on 2015-09-18 16:57  airycode  阅读(301)  评论(0编辑  收藏  举报

导航