博客列表 >jQuery基础-2018年4月3日14点20分

jQuery基础-2018年4月3日14点20分

旺小舞的博客
旺小舞的博客原创
2018年04月03日 15:22:26657浏览

一:jQuery 的两种引入方式

    1,在线引入:jq cdn有很多网站都提供,我们以百度为例

        在线链接:http://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js

        格式:

<script type="text/javascript" src="http://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js">	
</script>

    2,下载到本地进行在进行加载

        官网地址:jquery.com              下载链接  Download the uncompressed, development jQuery 3.3.1

    格式:<script type="text/javascript" src="jquery-3.3.1.js"></script>

二:$(document).read()使用方式与简写

引入jqery 库

    原生js代码:document.getElementByTagName('li')[0].style.backgroundColor = 'skyblue'

    jQuery函数:$('li:first-child').css('background-color','skylue')     //原生转为jQuery对象

 $('li')[0].style.backgroundColor='skyblue'/$('li').get(2).style.backgroundColor='skyblue' //jQuery转为原生连接原生语法

    // 原生转jquery对象 $()  选择第4+1个元素

    $('li:eq(4)').css('background-color','skyblue')

   三: jQuery进行元素查找和插入


        $('h2 span').css('background-color','red')

        $('p+p').html('找到元素并操作')

        // 可以创建一个html元素 var img = document.createElement('img') img.src =     appendChild(img)

          $('<img src="images/zly.jpg" width="100">').insertAfter('h2').css('border-radius','50%') </script>






声明:本文内容转载自脚本之家,由网友自发贡献,版权归原作者所有,如您发现涉嫌抄袭侵权,请联系admin@php.cn 核实处理。
全部评论
文明上网理性发言,请遵守新闻评论服务协议