jq 相同class内文本最大值
发布网友
发布时间:2022-04-24 09:03
我来回答
共1个回答
热心网友
时间:2022-06-18 08:36
<!DOCTYPE html>
<html>
<head>
<title>ttt</title>
<script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.js"></script>
</head>
<body>
<div class="20190215_value_1">123</div>
<div class="20190216_value_2">5465</div>
<div class="20190215_value_1">312</div>
<div class="20190216_value_2">787</div>
<div class="20190217_value_1">312</div>
<div class="20190217_value_2">787</div>
<script type="text/javascript">
$(function(){
var divArray = $("div").toArray();
var numArray = [];
for (var i = 0; i < divArray.length; i++) {
var num = $(divArray[i]).text();
numArray.push(num);
}
var max = Math.max.apply(null , numArray);
alert(max);
})
</script>
</body>
</html>