jQuery基本选择器

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <style type="text/css">
        .imgclass
        {
            width: 200px;
            height: 200px;
        }
        .imgclass1
        {
            width: 210px;
            height: 210px;
        }
        table tr td
        {
            width: 300px;
            height: 300px;
        }
    </style>
    <script src="jquery-1.9.1.js" type="text/javascript"></script>
    <script type="text/javascript">
        $(function () {
            $('#Button1').click(function () {
                //获取的是所有类型(tagname)为img的元素
                //$('img').hide(3000);
                //$('img').show(3000);

                //获取的是所有class属性的值为“imgclass”的元素
                //$('.imgclass').hide(3000);
                //$('.imgclass').show(3000);

                //获取文档中的所有元素
                //$('*').hide(2000);
                //$('*').css('background-color', 'Blue');

                //$('#img1,#img3,#Button2').hide(2000);
                //$("#img1,#img3,#Button2").show(2000);//一定是将所有id用一对''括起来,而不能每个id分别用引号括起来

                //多个选择器既可以是id,也可以是id,tagname和classname的混合体
                //$('#img1,#img3,input').hide(2000);
                //$("#img1,#img3,input").show(2000);
            })
            //改变图片样式
            $('#Button2').click(function () {
                $('#img2').removeClass();
                $('#img2').addClass('imgclass1');
            })
        })
    </script>
</head>
<body>
    <table>
        <tr>
            <td>
                <img id="img1" src="images/1.jpg" class="imgclass" />
            </td>
            <td>
                <img id="img2" src="images/2.jpg" class="imgclass" />
            </td>
        </tr>
        <tr>
            <td>
                <img id="img3" src="images/3.jpg" class="imgclass" />
            </td>
            <td>
                <img id="img4" src="images/4.jpg" class="imgclass" />
            </td>
        </tr>
    </table>
    <input id="Button1" type="button" value="玩儿" /><br />
    <input id="Button2" type="button" value="改变控件样式" /><br />
</body>
</html>

转载于:https://www.cnblogs.com/duanlinlin/archive/2013/04/17/3027033.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值