77 jQuery-使用$.inArray()函数搜索数组中指定元素的位置

版权声明:本文为大都督作者的原创文章,未经 大都督 允许也可以转载,但请注明出处,谢谢! 共勉! https://blog.csdn.net/qq_37335220/article/details/86562106

1.效果图

在这里插入图片描述

2.HTML代码

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>77 jQuery-使用$.inArray()函数搜索数组中指定元素的位置</title>
<style type="text/css">
	body{font-size: 13px;}
	ul{
		padding: 0px;
		margin: 20px;
		list-style-type: none;
		width: 260px;
		border-top: dashed 1px #ccc;
		border-left: dashed 1px #ccc;
		border-right: dashed 1px #ccc;
	}
	ul li{
		border-bottom: dashed 1px #ccc;
		padding: 8px;
	}
	.title{
		background-color: #eee;
		font-weight: bold;
	}
	div{
		margin: 20px;
		padding: 10px;
		border: solid 1px #666;
		background-color: #eee;
		width: 300px;
	}
</style>
</head>
<body>
	<div id="divTip">
	
	</div>
<script src="../jquery.min.js"></script>
<script type="text/javascript">
$(function(){
	var strTmp = "待搜索数据:";
	var arrNum = [0,17,72,3,4,5,6,7,8,9,10,0,1,2,3,4,5,6,7];
	//获取7在数组中第一次出现时的索引值
	var arrGet = $.inArray(7, arrNum);
	strTmp += arrNum.join();
	strTmp += "<br/>获取7在数组中第一次出现时的索引值?";
	strTmp += "<br>搜索后结果:"+arrGet;
	$("#divTip").append(strTmp);
})
</script>
</body>
</html>

猜你喜欢

转载自blog.csdn.net/qq_37335220/article/details/86562106
77