老师,为什么我按您教的代码运行不起来?
iUnicorn
iUnicorn 2019-03-19 15:14:55
0
5
1558

<!DOCTYPE html>
<html lang="zh-CN">
<head>
   <meta charset="UTF-8">
   <title>遍历jquery对象</title>
   <script src="../jquery-3.3.1.js"></script>
   <script>
$("button").click(function () {
           //$("li").css("color","red");
           //上面这行已注释的代码,使用this函数可以完成更多功能。
$("li").each(function (i) {
               $(this).css("color","red").html(i+"---"+"www.php.cn");
});
})
       
   </script>
</head>
<body>
   <button type="button" name="button">请点变色</button>
   <ul>
       <li>PHP中文网01</li>
       <li>PHP中文网02</li>
       <li>PHP中文网03</li>
       <li>PHP中文网04</li>
       <li>PHP中文网05</li>
   </ul>
</body>
</html>

iUnicorn
iUnicorn

知识,成就梦想!

全部回复(2)
Alone88

你js代码写在<body>上面需要需要添加入口函数的

  • 回复 应该是不需要的, script代码位置放在后面就好了。谢谢回复
    iUnicorn 作者 2019-03-20 17:00:15
小灰

<!DOCTYPE html>

<html lang="zh-CN">

<head>

<meta charset="UTF-8">

<title>遍历jquery对象</title>

</head>

<body>

<button type="button" name="button">请点变色</button>

<ul>

<li>PHP中文网01</li>

<li>PHP中文网02</li>

<li>PHP中文网03</li>

<li>PHP中文网04</li>

<li>PHP中文网05</li>

</ul>

</body>

<script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>

<script>

$("button").click(function () {

//上面这行已注释的代码,使用this函数可以完成更多功能。

$("li").each(function (i) {

$(this).css("color","red").html(i+"---"+"www.php.cn");

});

})

</script>

</html>


  • 回复 谢谢回复,位置换了一下解决了。再次感谢!!呵呵~~
    iUnicorn 作者 2019-03-20 16:59:33
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责声明 Sitemap
PHP中文网:公益在线PHP培训,帮助PHP学习者快速成长!