jQuery 标签选择器练习 评分空间和li控制

练习一

<!DOCTYPE html>

<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="utf-8" />
    <title></title>
    <style type="text/css">
        td {
        font-size:50px;
        color:green;
        cursor:pointer;
        font-family:SimHei;
        }
    </style>
    <script src="js/jquery-3.5.0.js"></script>
    <script type="text/javascript">
        $(function () {
            $('td').mouseover(function () {
                $(this).text('★').css('color', 'red').prevAll('td').text('★').css('color', 'red').end().nextAll('td').text('☆').css('color', '');
            }).mouseout(function () {
                $('td').text('☆').css('color', '');
                $('td[isclicked]').text('★').css('color', 'red').prevAll('td').text('★').css('color', 'red')
            }).click(function () {
                $(this).attr('isclicked', 'isclicked').siblings('td').removeAttr('isclicked');
                alert($(this).attr('score'));
                //$('td').unbind();//锁定,注销所有事件
            }).attr('score', function (index) {//隐式迭代
                return (index + 1) * 10;
            });
        });


    </script>
</head>
<body>
    <table>
        <tr>
            <td></td>
            <td></td>
            <td></td>
            <td></td>
            <td></td>
        </tr>
    </table>
</body>
</html>

练习二

<!DOCTYPE html>

<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="utf-8" />
    <title></title>
    <script src="js/jquery-3.5.0.js"></script>
    <script type="text/javascript">
        $(function () {
            $('li').mouseover(function () {
                $(this).css('background-color', 'red').siblings('li').css('background-color', '');
            }).click(function () {
                $(this).nextAll('li').css('background-color', 'blue').end().prevAll('li').css('background-color', 'yellow');//end()方法用于修复nextAll和prevAll破坏的链式编程
                $('li').unbind();//注销li标签的所有事件
            });
        });

    </script>

</head>
<body>
    <ul>
        <li>阿森纳</li>
        <li>巴塞罗那</li>
        <li>利物浦</li>
        <li>皇家马德里</li>
        <li>尤文图斯</li>
    </ul>
</body>
</html>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值