jquery each()循环

89463661 2019-12-23

<%@ page contentType="text/html;charset=UTF-8" language="java" %><html><head>    <title>Title</title>    <script src="js/jquery-3.2.1.min.js"></script>    <script src="js/jquery-migrate-1.4.1.js"></script>    <script>      $(function () {          var provence=$("ul>li");          provence.each(function (index,element) {              if("上海市"==$(element).html()){                  //返回false 相当于break  返回true 相当于continue                  return false;              }              alert(index+":"+$(element).html());          });      });    </script></head><body><div>    <ul>        <li>山东省</li>        <li>上海市</li>        <li>安徽省</li>        <li>山西省</li>        <li>陕西省</li>    </ul></div></body></html>

相关推荐

80437916 / 0评论 2020-01-23