jquery02

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8" />
        <title>课前抽查</title>
        <!-- 引入外部js=jquery类库-->
        <script src="js/jquery-3.3.1.js" type="text/javascript" charset="utf-8"></script>
        <!-- 另起一个script块 -->
          <script type="text/javascript">
              //页面载入函数
            $(function(){
                /* 抽查1:使用jquery方式点击按钮弹出文本框的值 */
                var b=$("#bb");
                b.click(function(){
                    var a=$("#aa").val();
                    alert(a)
                })
                /* 抽查2 */
                $("table tr:even").css("background-color","red");
                $("table tr:odd").css("background-color","yellow");
            
            })
            
            
          </script>
    </head>
    <body>
        <input type="text" id="aa"/>
        <input type="button" value="确定" id="bb"/>
        <table width="50%" border="1px">
        <tr>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
        </tr>
        <tr>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
        </tr>
        <tr>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
        </tr>
        <tr>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
        </tr>
        </table>
    </body>
</html>

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title>jquery02:$工具方法&属性css</title>
        <style type="text/css">
            .xx {
                border: solid red 5px;

            }

            .aaa {
                background-color: #00FFFF;
            }

            .bbb {
                background-color: burlywood;
            }
        </style>
        <script src="js/jquery-3.3.1.js" type="text/javascript" charset="utf-8"></script>
        <script type="text/javascript">
            $(function() {
                //1。$工具方法
                //1.1$.each()遍历数组.对象的数据
                //定义对象{}
                //             var stu={"name":"nb","age":38};
                //             //遍历对象
                //             // console.info(stu.name,stu.age)
                //             $.each(stu,function(v,j){//键 值
                //                 console.info(j)

                // })

                //             //定义数组[]
                //             var names=["abc","abcd","abvcd","acc"];
                //             //遍历数组
                //             $.each(names,function(i,n){//下标:元素
                //                 console.info(n)
                //             })

                //定义对象数组[{},{}]
                //             var stus=[{"name":"nb","age":38},{"name":"xnb","age":18}]
                //             //遍历对象数组
                //             $.each(stus,function(i,s){
                //                 // console.info(s.name,s.age)//方式1
                //                 $.each(s,function(k,v){方式2
                //                     console.info(v);
                //                     
                //                 })
                // })
                //             1.2 $.trim 去除前后空格
                //         var str="  zking  ";
                //         console.info($.trim(str).length)
                // 1.3 $.type()得到数据类型
                //                 var str="1";
                //                 console.info($.type(str))
                //                 1.4 $.isfunction()//判断是否是函数
                //                 
                // 1.5 $.isArray()//判断是否是数组
                // var stus=[{"name":"nb","age":38},{"name":"xnb","age":18}]
                //             
                //             var names=["abc","abcd","abvcd","acc"];
                //             console.info($.isArray(names))
                // console.info($.isFunction(mya))

                // 1.6 $.parseJSON() 解析json格式的字符串-->js的数组/对象
                //定义对象字符串
                // var stuStu='{"name":"nb","age":38}';
                // 将字符串转为对象
                // var stu=$.parseJSON(stuStu);
                //             console.info($.type(stuStu))
                //             console.info(stu.name,stu.age);
                //             $.each(stu,function(i,v){
                //                 console.info(v);
                //             })
                //遍历对象数组
                //             $.each(stus,function(i,v){
                //                 console.info(v.name,v.age);
                //                 
                //             })


                // 2.属性和css
                // 2.1 attr()拿值 设值
                //             var mpath=$("#aa").attr("src")
                //             console.info(mpath);//拿值

                //设置属性值
                //             $("#aa").attr("src","img/2.jpg")
                //             $("#aa").attr("width","500px")

                // 2.2 removeAttr()移除属性值
                // $("#aa").removeAttr("width");
                // $("#aa").removeAttr("src");

                // 2.3 addClass()动态增加样式
                // $("#aa").addClass("xx")//样式的叠加
                // $("#aa").attr("class","xx")//样式的替换

                // 2.4 removeClass()删除对应样式
                // $("#aa").removeClass("xx");

                // 2.5 prop和attr的区别  prop属性值是boolean类型的时候
                // 给图片增加name值
                // $("#aa").attr("name","abc");
                //             $("#aa").prop("name","abc");
                //             
                //             $("#ok").click(function(){
                //                 $(".abc").prop("checked",true);
                //                 
                //             })
                //             
                //             $("#nook").click(function(){
                //                 $(".abc").prop("checked",false);
                //                 
                //             })
                //             
                //案例3:优化表格隔行换色
//                 $("table tr:even").addClass("aaa")
//                 $("table tr:odd").addClass("bbb")
// 
//       2.6 html()和text()的区别
//          var a=$("p").html();//会包含子标签
//          console.info(a);
//           var b=$("p").text();//只会打印纯文本
//           console.info(b);

       // 2.7 val()拿值 设值
                //拿到文本框的value值
//                  var a= $("#bf").val();
//          console.info();
//       赋值
           // $("#bf").val("hhhh")
     
            // /CSS
                        // 1.设置值
                        // $("p").css("background","rgb(111,111,111)");//单属性
                        // $("p").css({"background":"yellow","color":"red"});//多属性
                        
                        //2 拿值
//              var a= $("p").css("background"); 
//                          console.info(a);
            })

//             function mya() {
//                 alert(13)
//             }
        </script>

    </head>
    <body>
        <input type="text" value="wanj" id="bf"/>
        <p>心疼好好<span>huu</span></p>
        <img src="img/1.jpg" width="300px" id="aa" class="yy" />
        <hr />
        <input type="button" value="全选" id="ok" />
        <input type="button" value="取消全选" id="nook" />
        <input type="checkbox" class="abc" value="植物讲述" />植物讲述
        <input type="checkbox" class="abc" value="植物讲述1" />植物讲述1
        <input type="checkbox" class="abc" value="植物讲述2" />植物讲述2
        <table border="1px" width="50%">
            <tr>
                <td>&nbsp;</td>
                <td>&nbsp;</td>

            </tr>
            <tr>
                <td>&nbsp;</td>
                <td>&nbsp;</td>

            </tr>
            <tr>
                <td>&nbsp;</td>
                <td>&nbsp;</td>

            </tr>
            <tr>
                <td>&nbsp;</td>
                <td>&nbsp;</td>

            </tr>
            <tr>
                <td>&nbsp;</td>
                <td>&nbsp;</td>

            </tr>

        </table>
        <pre>


       </pre>

    </body>
</html>

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值