2018-5-5 学习进度

一、了解jQuery

jQuery是一个js函数库,可以看作它实现的就是js,但从代码上看更简单了。
1.html 的元素选取
一个格式上的$(" ") 认识了选择器,相当与原生js中通过document.getElement......来获取的功能
对html元素的操作也是类似的

2.常用jQuery事件
$(document).ready()
$("p").dblclick(function(){ $(this).hide();});

3.认清jQuery对象与DOM对象的差异
通过jQuery包装后的对象是一个类数组对象
jQuery是一个类数组对象,而DOM对象就是一个单独的DOM元素。

4.索引的注意:
jQuery实现:nth-child(n)从1开始计数,:nth-child(index)从1开始的,而eq(index)是从0开始的
nth-child(n) 与 :nth-last-child(n) 的区别前者是从前往后计算,后者从后往前计算

额。。还没有写demo

二、完善自己以前写的小例子

1.百度首页

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>百度一下,你就知道</title>
    <link rel="shortcut icon" type="images/x-icon" href="http://www.baidu.com/favicon.ico">
    <style>
        .top {
            width:100%;
            height:40px;
        }

        .top>.title {
            height:40px;
            float:right;
        }

        .top>.title>span
        {
            line-height:40px;
            float:right;
        }

        .top>.title>span>a {
            font-size:13px;

            text-decoration:underline;
            color:#333;
        }

        .setWide {
            font-weight:bold;
        }

        .product-list {
            display: inline;
            margin:0;
        }

        .more-product {
            border:0;
            height:25px;
            width:65px;
            font-size: 14px;
            background: rgba(51, 102, 255, 0.82);
            color:#fff;
            text-align: center;
        }

        .list {
            position: fixed;
            top: 0;
            bottom: 0;
            right: 0;
            width: 90px;
            background-color: #f9f9f9;
            color: #000;
            text-align: center;
            border-left: 1px solid #e7e7e7;
            transform: translate3d(100px,0,0);
            padding-top: 50px;
        }

        .list span {
            border-top: rgba(191, 191, 191, 0.44) solid 1px ;
            text-align: center;
            display: block;
            padding: 10px
        }

        .product-list:hover .more-product {
            background: transparent;
            color: #333;
        }

        .product-list:hover .list {
            transform: translate3d(0,0,0);
            z-index: -1;
        }

        .list span a {
            font-size: 14px;
            text-decoration: none;
        }

        .pic{
            text-align:center;
        }

        .logo{
            height:130px;
        }

        .foot {
            text-align: center;
        }

        .foot>a {
            width:100%;
            text-align: center;
            font-size:12px;
            color:darkgray;
            margin-bottom: 10px;
            text-decoration: underline;
        }

        .foot>.Line {
            text-decoration: underline;
        }

        .bottom {
            color:#767376;
            padding-top: 0;
            width:100%;
            text-align: center;
            font-size:12px;
        }

        .bottom>p {
            margin:0;
            line-height: 40px;
            color:#767376;
        }

        .bottom>p>a {
            text-decoration: underline;
            color: #767376;
        }

        .icp,
        .gongan {
            width: 14px;
            height: 17px;
            display: inline-block;
            overflow: hidden;
            background: url(https://ss1.bdstatic.com/5eN1bjq8AAUYm2zgoY3K/r/www/cache/static/protocol/https/global/img/icons_5859e57.png) no-repeat;
        }

        .icp {
            background-position: -600px -96px;
            position: relative;
            top: 3px;
        }
        .gongan {
            background-position: -623px -96px;
            position: relative;
            top: 3px;
        }

        #search-text {
            width: 540px;
            height: 36px;
            box-sizing: border-box;
            margin-left: 355px;
            margin-top: 3px;
            text-indent: 4px;
        }

        #search-button {
            width: 100px;
            height: 36px;
            background: #3385FF;
            border: 0;
            letter-spacing: 1px;
            color: white;
            margin-left: -5px;
            font-size: 15px;
            box-sizing: border-box;
            transform: translateY(2px);
            -webkit-box-sizing: border-box;
        }

        #search-button:hover {
            cursor: pointer;
        }

        #suggest {
            width: 540px;
            margin: 0;
            padding: 0;
            margin-left: 355px;
            list-style: none;
            display: none;
            border: 1px solid #E3E5E4;
        }

        #suggest li {
            line-height: 36px;
            background: white;
        }

        #suggest li:hover {
            background: #F0F0F0;
        }

        .li1 {
            text-indent: 4px;
        }

    </style>

</head>
<body>

<div class="top">
    <div class="title">
        <span>
            <a class="setWide" href="http://news.baidu.com/">新闻</a>&nbsp;&nbsp;&nbsp;
            <a class="setWide" href="https://www.hao123.com/">hao123</a>&nbsp;&nbsp;&nbsp;
            <a class="setWide" href="https://map.baidu.com/">地图</a>&nbsp;&nbsp;&nbsp;
            <a class="setWide" href="http://v.baidu.com/">视频</a>&nbsp;&nbsp;&nbsp;
            <a class="setWide" href="https://tieba.baidu.com/index.html">贴吧</a>&nbsp;&nbsp;&nbsp;
            <a class="setWide" href="http://xueshu.baidu.com/">学术</a>&nbsp;&nbsp;&nbsp;
            <a href="https://passport.baidu.com">登录</a>&nbsp;&nbsp;&nbsp;
            <a class="setting"><a href="#">设置</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            </a>
            <div class="product-list">
                <input class="more-product" type="submit" value="更多产品" name="submit" />
                <div class="list">
                    <span>
                <img src="#" style="width:30px;height:30px;" alt="" ><br><a href="https://www.nuomi.com/?cid=002540">糯米</a>
            </span>
            <span>
                <img src="#" style="width:30px;height:30px;" alt="" ><br><a href="http://music.baidu.com/">音乐</a>
            </span>
            <span>
                <img src="#" style="width:30px;height:30px;" alt="" ><br><a href="https://zhidao.baidu.com/">知道</a>
            </span>
            <span>
                <img src="#" style="width:30px;height:30px;" alt="" ><br><a href="https://wenku.baidu.com/">文库</a>
            </span>
            <span>
                <img src="#" style="width:30px;height:30px;" alt="" ><br><a href="http://top.baidu.com/">风云榜</a>
            </span>
            <span>
                <a href="http://top.baidu.com/" style="font-size: 12px;">全部产品>></a>
            </span>
                </div>
            </div>
        </span>
    </div>
</div>

<div class="pic">
    <img class="logo" src="http://www.baidu.com/img/bd_logo1.png" title="点击一下,了解更多"/>
</div>
<br/>
<div class="main-search">
    <form>
        <input id="search-text" type="text" name="search" value="" />
        <input id="search-button" type="button" name="submit" value="百度一下" />
        <ul id="suggest">
            <li class="li1" onclick="show_it(this.id)"></li>
            <li class="li1" onclick="show_it(this.id)"></li>
            <li class="li1" onclick="show_it(this.id)"></li>
            <li class="li1" onclick="show_it(this.id)"></li>
            <li class="li1" onclick="show_it(this.id)"></li>
            <li class="li1" onclick="show_it(this.id)"></li>
            <li class="li1" onclick="show_it(this.id)"></li>
            <li class="li1" onclick="show_it(this.id)"></li>
            <li class="li1" onclick="show_it(this.id)"></li>
            <li class="li1" onclick="show_it(this.id)"></li>
        </ul>
    </form>
</div>
<br><br><br><br><br><br><br><br>
<div class="c-img" style="text-align: center;">
    <img src="https://ss1.bdstatic.com/5eN1bjq8AAUYm2zgoY3K/r/www/cache/static/protocol/https/home/img/qrcode/zbios_efde696.png" ><br>
    <span style="font-size: 12px;font-weight: bold;color:dimgrey" >百度</span>
</div>
<br>
<div class="foot">
    <a href="https://www.baidu.com/cache/sethelp/help.html" >把百度设为主页</a>&nbsp;&nbsp;&nbsp;&nbsp;
    <a href="http://home.baidu.com/">关于百度</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <a class="Line" href="http://ir.baidu.com">About Baidu</a>&nbsp;&nbsp;&nbsp;
    <a href="http://e.baidu.com/?refer=888">百度推广</a>
</div>
<div class="bottom">
    <p>
        ©2018 Baidu <a href="http://www.baidu.com/duty/" style="margin: 0 3px">使用百度前必读</a>
        <a href="http://jianyi.baidu.com/" style="margin: 0 3px">意见反馈</a> 京ICP证030173号
        <i class="icp"></i>
        <a href="http://www.beian.gov.cn/portal/registerSystemInfo?recordcode=11000002000001">京公网安备11000002000001号</a>
        <i class="gongan"></i>
    </p>
</div>
<script>
    var oText = document.getElementById("search-text");
    oSug = document.querySelector("#suggest");
    lis = document.getElementsByClassName("li1");

    // 当在input框中键盘弹起触发
    oText.onkeyup = function(){
        oSug.style.display = oText.value?"block":"none";
        var osc = document.createElement("script");
        // 引入百度的url,然后将oText文本框中输入的内容连接到url,在后面在运行自己的方法,同时也完成页面跳转完成搜索的核心
        osc.src = "https://sp0.baidu.com/5a1Fazu8AA54nxGko9WTAnF6hhy/su?wd="+oText.value+"&cb=record";

        document.body.appendChild(osc);

        //按下回车跳转页面
        if(event.keyCode===13){
            window.location.href = "https://www.baidu.com/s?ie=utf-8&f=8&rsv_bp=1&rsv_idx=1&tn=baidu&wd="+oText.value;
        }
    };

    var count = 0;
    var search = 0;
    var arr = oSug.children;
    function record(json){
        var jsonLength = 0;
        for(var x in json.s){
            jsonLength++;
        }
        for(var i=0;i<lis.length;i++){
            if(jsonLength===0){
                arr[i].innerHTML = null;
            }else{
                if(json.s[i]!=null){
                    arr[i].innerHTML = json.s[i];
                }
            }
        }
        if(count===lis.length-1){
            count=0;
            search=0;
        }
        count++;
        search++;
    }

    //单击li中的值显示在input框中
    function show_it(e){
        oText.value = arr[e].innerHTML;
        window.location.href = "https://www.baidu.com/s?ie=utf-8&f=8&rsv_bp=1&rsv_idx=1&tn=baidu&wd="+oText.value;
    }
    //单击body中的任意地方可以隐藏li
    document.body.onclick = function(){
        oSug.style.display = "none";
    };

    //单击百度btn的时候触发,并跳到新的连接
    var button = document.querySelector("#search-button");
    button.onclick = function(){
        var oText = document.getElementById("search-text").value;
        window.location.href = "https://www.baidu.com/s?ie=utf-8&f=8&rsv_bp=1&rsv_idx=1&tn=baidu&wd="+oText;
    }
</script>
</body>
</html>

2.文字查找替换
(上个学期的新生作业里的)

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>文字查找替换</title>
    <style>
        #box {
            border: 1px solid grey;
            width: 600px;
            margin: 0 auto;
        }
        .means {
            display: inline-block;
        }
        span {
            background: #ffa185;
        }
    </style>
</head>
<body>
<div id="box">
    <div class="means">
        <form>
        查找:<input type="text" />
        替换:<input type="text" />
            <input type="button" value="查找" />
            <input type="button" value="替换" />
        </form>
    </div>
        <br>
    <div>
        <p>生活是人间在繁华的演出,沉睡是所有故事的收尾、谁不是生命的漫游者?
            谁没在云端闲情过?
            生命,只是一场唯有一次的真实梦境。
            新的阳光里,香樟哭了,那些忧伤化作清晨的雾被蒸干了。
            因为有阳光的揩拭,香樟才敢放肆泪珠,那么,我的眼泪呢?
        </p>
    </div>
</div>
<script>
    window.onload = function () {
        var oInput = document.getElementsByTagName("input");
        var p = document.getElementsByTagName("p")[0];
        var str = p.innerHTML;

        oInput[2].onclick = function () {
            var finder = oInput[0].value;
            if (str.indexOf(finder)===-1) {
                alert ("没有找到!")
            }
            else {
                var show = str.split(finder).join("<span>" + finder + "</span>");
                //显示结果
                p.innerHTML = show;
            }
        }

        oInput[3].onclick = function () {
            var finder = oInput[0].value;
            var change = oInput[1].value;
            var show = str.split(finder).join("<span>"+change+"</span>");
            //显示结果
            p.innerHTML = show;
        }
    }
</script>
</body>
</html>

这之前的尝试的实例中领略了CSS对页面布局样式的作用,在这个例子中则认识到JS在功能上的实现,类似的还有选项卡的切换功能......

3.文字搬运
(这个还差一点,快了。。)

©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 159,458评论 4 363
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 67,454评论 1 294
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 109,171评论 0 243
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 44,062评论 0 207
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 52,440评论 3 287
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 40,661评论 1 219
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 31,906评论 2 313
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 30,609评论 0 200
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 34,379评论 1 246
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 30,600评论 2 246
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 32,085评论 1 261
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 28,409评论 2 254
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 33,072评论 3 237
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 26,088评论 0 8
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 26,860评论 0 195
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 35,704评论 2 276
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 35,608评论 2 270

推荐阅读更多精彩内容

  • 一、样式篇 第1章 初识jQuery (1)环境搭建 进入官方网站获取最新的版本 http://jquery.co...
    凛0_0阅读 3,281评论 0 44
  • 原文链接 http://blog.poetries.top/2016/10/20/review-jQuery 关注...
    程序员poetry阅读 16,583评论 18 503
  • jQuery基础(一)——样式篇 1-2环境搭建 1-3 jQuery HelloWorld体验 $(docume...
    croyance0601阅读 1,048评论 0 8
  • 1.JQuery 基础 改变web开发人员创造搞交互性界面的方式。设计者无需花费时间纠缠JS复杂的高级特性。 1....
    LaBaby_阅读 1,101评论 0 1
  • 1.JQuery 基础 改变web开发人员创造搞交互性界面的方式。设计者无需花费时间纠缠JS复杂的高级特性。 1....
    LaBaby_阅读 1,285评论 0 2