jQuery21(文本框为空,球队)

文本框为空练习

完整实例:

<!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>
    <script src="jquery-1.8.3.js" type="text/javascript"></script>
    <script type="text/javascript">
        //创建若干个输入文本框,当光标离开文本框的时候,如果文本框为空,则将文本框背景色设置为红色,如果不为空则为白色
        $(function () {
            $('input').blur(function () {
                if ($(this).val().length > 0) {
                    $(this).css('backgroundColor', 'red')
                } else {
                    $(this).css('backgroundColor', 'white');
                }
            });
        });
    </script>
</head>
<body>
    <input type="text" name="name" value="" />
    <input type="text" name="name" value="" />
    <input type="text" name="name" value="" />
    <input type="text" name="name" value="" />
    <input type="text" name="name" value="" />
    <input type="text" name="name" value="" />
    <input type="text" name="name" value="" />
    <input type="text" name="name" value="" />
    <input type="text" name="name" value="" />
    <input type="text" name="name" value="" />
</body>
</html>

球队练习.unbind

知识点:unbind,取消事件,另外,style也是一个属性,可以删除.
完整实例:

<!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>
    <script src="jquery-1.8.3.js" type="text/javascript"></script>
    <script type="text/javascript">
        $(function () {
            //            $('ul li').mouseover(function () {
            //                $(this).css('backgroundColor', 'red');
            //            }).mouseout(function () {
            //                $(this).css('backgroundColor', '');
            //            }).click(function () {
            //                $(this).removeAttr('style').unbind().appendTo($('#u2'));
            //                //得删除样式
            //                //取消他的时间 unbind
            //            });
            $('ul li').mouseover(function () {
                $(this).css('backgroundColor', 'red');
            }).mouseout(function () {
                $(this).css('backgroundColor', '');
            }).click(function () {
                $(this).removeAttr('style').appendTo($(this).parent().siblings('ul'));
                //parent() 父亲节点
                //siblings 兄弟节点
                //注意,hr也算他的兄弟节点,所以需要在括号内加上'ul'

            });

        });
    </script>
</head>
<body>
    <ul id='u1'>
        <li>1</li>
        <li>2</li>
        <li>3</li>
        <li>4</li>
        <li>5</li>
        <li>6</li>
        <li>7</li>
        <li>8</li>
    </ul>
    <hr color='red' />
    <ul id='u2'>
    </ul>
</body>
</html>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值