目录

  • 1 JavaScript快速入门
    • 1.1 如何插入javascrip代码
    • 1.2 引用javascritp外部文件
    • 1.3 JavaScript在页面中位置
    • 1.4 JavaScript语句和符号
    • 1.5 JavaScript注释
    • 1.6 案例1-1 script标签在html中书写位置
    • 1.7 案例1-2  JavaScript引入方式
    • 1.8 JavaScript变量
    • 1.9 JavaScript判断语句
    • 1.10 JavaScript函数
    • 1.11 案例1-4 比较两个数大小
    • 1.12 案例1-8 改变网页皮肤颜色
    • 1.13 案例1-9 验证用户名和密码
  • 2 基本语法
    • 2.1 变量
      • 2.1.1 标识符
      • 2.1.2 保留关键字
      • 2.1.3 变量的使用
      • 2.1.4 变量的赋值
    • 2.2 变量的数据类型
      • 2.2.1 数据类型分类
      • 2.2.2 基本数据类型
      • 2.2.3 数据类型检测
      • 2.2.4 数据类型检测总结
      • 2.2.5 数据类型转换
      • 2.2.6 数据类型转换(程序1)
      • 2.2.7 数据类型转换(程序2)
      • 2.2.8 数据类型转换(程序3)
      • 2.2.9 数据类型转换(程序4)
      • 2.2.10 数据类型转换(程序5)
      • 2.2.11 数据类型转换(程序6)
    • 2.3 表达式
    • 2.4 运算符
      • 2.4.1 算数运算符
      • 2.4.2 字符串运算符
      • 2.4.3 赋值运算符
      • 2.4.4 比较运算符
      • 2.4.5 逻辑运算符
      • 2.4.6 三元运算符
      • 2.4.7 位运算符
      • 2.4.8 运算符优先级
    • 2.5 流程控制
      • 2.5.1 选择结构
      • 2.5.2 if单分支语句
      • 2.5.3 if...else双分支语句
      • 2.5.4 if...else双分支举例
      • 2.5.5 if...else多路分支语句
      • 2.5.6 if...else多路分支举例
      • 2.5.7 switch...case多路分支
      • 2.5.8 while循环语句
      • 2.5.9 do...while语句
      • 2.5.10 for语句
      • 2.5.11 JavaScript break 和 continue 语句
      • 2.5.12 九九乘法表
      • 2.5.13 判断素数
      • 2.5.14 判断红白黑球个数
  • 3 数组
    • 3.1 初始数组
    • 3.2 创建数组
    • 3.3 数组的基本操作
    • 3.4 常见二维数组操作
    • 3.5 数组排序
      • 3.5.1 冒泡排序
      • 3.5.2 选择排序
      • 3.5.3 插入排序
    • 3.6 常见数组方法
    • 3.7 案例 猴子选大王
    • 3.8 案例 省份城市的三级联动
  • 4 函数
    • 4.1 函数的定义与调用
    • 4.2 变量的作用域
    • 4.3 匿名函数
    • 4.4 嵌套与递归
    • 4.5 闭包函数
  • 5 对象
    • 5.1 面向对象概述
    • 5.2 自定义对象
    • 5.3 构造函数
    • 5.4 内置对象
      • 5.4.1 String对象
      • 5.4.2 Number对象
      • 5.4.3 Math对象
      • 5.4.4 Date对象
  • 6 BOM
    • 6.1 什么是BOM
    • 6.2 window对象
      • 6.2.1 弹出窗口
      • 6.2.2 窗口打开关闭
      • 6.2.3 定时器
      • 6.2.4 限时秒杀
    • 6.3 location对象
    • 6.4 history对象
    • 6.5 navigator对象
    • 6.6 screen对象
    • 6.7 动手实践
      • 6.7.1 限时秒杀
      • 6.7.2 定时跳转
      • 6.7.3 红绿灯倒计时
      • 6.7.4 显示时间与日期
  • 7 DOM
    • 7.1 DOM对象简介
    • 7.2 HTML元素操作
    • 7.3 DOM节点操作
    • 7.4 轮播特效
    • 7.5 购物车实现方法1
      • 7.5.1 购物车结构
      • 7.5.2 购物车样式
      • 7.5.3 购物车业务逻辑
    • 7.6 购物车实现方法2
      • 7.6.1 结构页面
      • 7.6.2 样式
      • 7.6.3 页面逻辑
    • 7.7 案例应用
      • 7.7.1 改变盒子大小
      • 7.7.2 标签栏切换效果
      • 7.7.3 列表的增删和移动
      • 7.7.4 我的购物车
    • 7.8 京东
  • 8 事件
    • 8.1 事件处理
      • 8.1.1 代码
      • 8.1.2 举例
    • 8.2 事件对象
      • 8.2.1 冒泡处理
      • 8.2.2 target与currentTarget
      • 8.2.3 禁止粘贴、右键、复制、剪切
    • 8.3 事件操作
      • 8.3.1 页面事件
      • 8.3.2 鼠标事件
      • 8.3.3 键盘事件
      • 8.3.4 表单事件
    • 8.4 图片无缝滚动
    • 8.5 看了又看
    • 8.6 放大镜
    • 8.7 商品详情页放大镜效果
      • 8.7.1 页面结构
      • 8.7.2 页面样式
      • 8.7.3 页面逻辑
    • 8.8 飘动的广告
    • 8.9 猜拳游戏
    • 8.10 瀑布流
    • 8.11 手风琴效果
  • 9 表单
    • 9.1 任务导学
    • 9.2 知识准备
      • 9.2.1 认识表单
      • 9.2.2 表单控件
    • 9.3 任务实现
      • 9.3.1 制作登录表单
      • 9.3.2 制作注册表单
      • 9.3.3 制作考试界面表单
    • 9.4 拓展阅读
    • 9.5 动手练习
  • 10 正则表达式
    • 10.1 认识正则表达式
    • 10.2 字符类别与集合
    • 10.3 字符限定与分组
    • 10.4 与正则相关的方法
    • 10.5 页面注册
      • 10.5.1 注册页面结构
      • 10.5.2 注册页面样式
      • 10.5.3 注册页面逻辑
    • 10.6 身份证验证
    • 10.7 成员注册
  • 11 初识jQuery
    • 11.1 jQuery课程简介
    • 11.2 jQuery的引入.html
    • 11.3 jQuery实现第一页面
    • 11.4 jQuery对象与DOM对象
    • 11.5 jQuery对象转化成DOM对象
    • 11.6 DOM对象转化成jQuery对象
  • 12 jQuery选择器
    • 12.1 jQuery选择器之ID选择器
    • 12.2 jQuery选择器之类选择器
    • 12.3 jQuery选择器之标签选择器
    • 12.4 jQuery选择器之全局选择器
    • 12.5 jQuery选择器之层级选择器
    • 12.6 jQuery选择器之组合选择器
    • 12.7 jQuery选择器之基本过滤选择器
    • 12.8 jQuery选择器之内容过滤选择器
    • 12.9 jQuery选择器之属性过滤选择器
    • 12.10 ​jQury选择器之可见选择器
    • 12.11 jQuery选择器之表单元素选择器
    • 12.12 jQuery选择器之表单对象属性选择器
    • 12.13 jQuery选择器之子元素过滤选择器
    • 12.14 jQuery子元素过滤选择器补充
    • 12.15 jQuery选择器之特殊选择器$(this)
    • 12.16 视频
  • 13 jQuery属性与样式
    • 13.1 jQuery属性与样式之.arrt()与removeAttr()
    • 13.2 jQuery属性与样式之.html()与.text()
    • 13.3 jQuery属性与样式之.val()
    • 13.4 jQuery属性与样式之样式的操作
    • 13.5 jQuery属性与样式之.css()
    • 13.6 jQuery尺寸方法
    • 13.7 jQuery的offset()方法
    • 13.8 jQuery之checkbox各种选中操作
  • 14 jQueryDOM操作
    • 14.1 jQueryDOM的创建
    • 14.2 jQuery元素内插入节点的方法
    • 14.3 jQuery元素外插入节点的方法
    • 14.4 jQuery节点的删除方法
    • 14.5 jQuery节点的复制方法
    • 14.6 jQuery节点的替换方法
    • 14.7 jQuery节点的包裹方法6
    • 14.8 修改文档结构视频
  • 15 jQuery遍历
    • 15.1 jQuery遍历祖先节点的方法
    • 15.2 jQuery遍历后代节点的方法
    • 15.3 jQuery遍历同胞节点的方法
    • 15.4 jQuery遍历之基本过滤方法
    • 15.5 jQuery遍历之高级过滤方法
    • 15.6 jQuery实现新闻滚动
    • 15.7 jQuery实现选项卡
  • 16 jQuery效果
    • 16.1 jQuery效果-隐藏与显示
    • 16.2 jQuery效果-逐个显示与隐藏
    • 16.3 jQuery效果-淡入淡出
    • 16.4 jQuery效果-滑动
    • 16.5 jQuery效果-动画
    • 16.6 jQuery效果-手动轮播
    • 16.7 jQuery效果-自动轮播
    • 16.8 动画效果视频
  • 17 jQuery事件
    • 17.1 jQuery鼠标事件之click与dblclick事件
    • 17.2 jQuery鼠标事件之mousedown与mouseup事件
    • 17.3 jQuery鼠标事件之mouseenter与mouseleave事件
    • 17.4 jQuery鼠标事件之mouseover与mouseout事件
    • 17.5 jQuery鼠标事件之hover
    • 17.6 jQuery鼠标事件之mousemove事件
    • 17.7 jQuery鼠标事件之focusin与focuout事件
    • 17.8 jQuery表单事件之focus与blur事件
    • 17.9 jQuery表单事件之select事件
    • 17.10 jQuery表单事件之submit事件
    • 17.11 jQuery表单事件之change事件
    • 17.12 jQuery事件举例-轮播
    • 17.13 jQuery事件的绑定
    • 17.14 jQuery事件委托
    • 17.15 jQuery事件冒泡的处理
    • 17.16 jQuery键盘事件之keyup、keydown、keypress事件
    • 17.17 通过键盘事件控制元素移动
    • 17.18 通过jQuery键盘事件进行表单元素验证
    • 17.19 事件处理视频
  • 18 jQuery案例
    • 18.1 jQuery案例一无缝滚动
    • 18.2 jQuery案例二放大镜
    • 18.3 jQuery案例三瀑布流
    • 18.4 jQuery案例四简单的树形菜单
    • 18.5 jQuery案例五居中放大
    • 18.6 jQuery案例六右侧在线客服
    • 18.7 jQuery案例七五星评分
    • 18.8 jQuery案例八抽奖
    • 18.9 jQuery案例九购物车
    • 18.10 jQuery案例十手风琴
    • 18.11 jQuery案例十一轮播
    • 18.12 jQuery案例十二进度条
    • 18.13 jQuery案例十三普通图表
    • 18.14 jQuery案例十三数组图表
    • 18.15 jQuery案例十三多数组图表
    • 18.16 jQuery案例十四轮播与手风琴结合
    • 18.17 jQuery案例十五滚动楼层效果
    • 18.18 jQuery案例十六右侧悬浮楼层滚动
    • 18.19 jQuery仿天猫页面楼层跳转
  • 19 jQueryMoblie基础
    • 19.1 jqueryMoblie HelloWorld
    • 19.2 jQueryMoblie按钮
    • 19.3 jQueryMoblie列表
  • 20 jQuerymobile案例
    • 20.1 作品展示
    • 20.2 可折叠列表
    • 20.3 可折叠集合
    • 20.4 多级折叠
    • 20.5 搜索过滤
  • 21 实训
    • 21.1 JavaScript程序设计实训内容及要求
    • 21.2 实训报告
  • 22 补考学习内容
    • 22.1 补考须知
jQuery案例七五星评分

图标:

<!doctype html>

<html>

<head>

<meta charset="utf-8">

<title>17.7jQuery案例七五星评分</title>

<style>

*{

margin:0;

padding:0;

}

li{

list-style-type:none;

}

#starWrap li{

float:left;

position:relative;

width:44px;

height:42px;

margin-right:10px;

cursor:pointer;

}

.height{ background-image:url(imgs/star1.png); }

.noheight{ background-image:url(imgs/star.png); }

#score{ 

clear:both;

height:42px;

width:44px;

text-align:center;

line-height:42px;

font-size:16px;

font-weight:bolder;

}

</style>

<script src="test/jquery-3.1.1.min.js"></script>

<script>

$(function(){

   var score = 0;

$('#starWrap li').mouseenter(function(){

var index = $(this).index();

console.log(index);

$(this).removeClass('noheight').addClass('height')

      .prevAll('li').removeClass('noheight').addClass('height');

$(this).nextAll('li').removeClass('height').addClass('noheight');

var s = (index+1)*2;

$('#score').html(s.toFixed(1)+'分');

});

$('#starWrap li').mouseleave(function(){

var $cur = $('#starWrap li.current');

if(score>0)

{

$cur.removeClass('noheight').addClass('height')

$cur.prevAll('li').removeClass('noheight').addClass('height');

$cur.nextAll('li').removeClass('height').addClass('noheight');

$('#score').html(score.toFixed(1)+'分');

}

else

{$('#starWrap li').removeClass('height').addClass('noheight');

$('#score').html('0.0分');

}

});

$('#starWrap li').click(function(){

$(this).addClass('current')

      .siblings().removeClass('current');

   var index = $(this).index();

score = (index+1)*2;

$('#score').html(s.toFixed(1)+'分');

});


});

</script>

</head>


<body>

<ul id="starWrap">

   <li class="noheight"></li>

   <li class="noheight"></li>

   <li class="noheight"></li>

   <li class="noheight"></li>

   <li class="noheight"></li>   

</ul>

<div id="score">0.0分</div>

</body>

</html>


//////////////////////////////////////////////////////

<!DOCTYPE html>

<html lang="en">

<head>

<meta charset="UTF-8">

<title>jQuery简单实用的五角星评分特效 </title>


<style>

* {

padding: 0;

margin: 0;

}


.comment {

font-size: 40px;

color: darksalmon;

margin:0 auto; width:200px; height:100px;

}


.comment li {

float: left;

cursor:pointer;

}


ul {

list-style: none;

}

</style>


<script src="js/jquery3.3.1.min.js"></script>

<script>

$(function () {

var wjx_s = "★";

var wjx_k = "☆";

//1. 给所有的li注册mouseenter事件

$(".comment li").mouseenter(function () {

//2. 让当前li和前面所有的li变成实心,让后面所有的兄弟变成空心

//前面兄弟:prevAll():

//后面兄弟:nextAll():

$(this).text(wjx_s).prevAll().text(wjx_s);

$(this).nextAll(wjx_k);

});

//2. 离开ul的时候,把所有的li变成空心

$(".comment").mouseleave(function () {

$(this).children().text(wjx_k);

//如果我知道了我刚刚点了那个五角星

//可以让点的那个五角星以及前面的兄弟变成实心就可以。

//4. 找到我点击的那个li

$("li.current").text(wjx_s).prevAll().text(wjx_s)

});

//3. 给所有的li注册点击事件,点击的时候,留下点东西(class)

$(".comment li").click(function () {

$(this).addClass("current").siblings().removeClass("current")

})

})

</script>


</head>

<body>

<br><br><br>

<ul class="comment">

<li>☆</li>

<li>☆</li>

<li>☆</li>

<li>☆</li>

<li>☆</li>

</ul>

</body>

</html>

初始效果图


鼠标单击第三个星效果


/////////////////////////////////////////////////

<!DOCTYPE html>

<html lang="en">

<head>

<meta charset="UTF-8">

<title>jQuery鼠标滑过五角星打分星级评分代码</title>

<script src="js/jquery.js"></script>

<link rel="stylesheet" type="text/css" href="css/css.css">


</head>

<body>


<div id="starRating">

    <p class="photo">

        <span><i class="high"></i><i class="nohigh"></i></span>

        <span><i class="high"></i><i class="nohigh"></i></span>

        <span><i class="high"></i><i class="nohigh"></i></span>

        <span><i class="high"></i><i class="nohigh"></i></span>

        <span><i class="high"></i><i class="nohigh"></i></span>

    </p>

    <p class="starNum">0.0分</p>

    <div class="bottoms">

        <a class="garyBtn cancleStar">取消评分</a>

        <a class="blueBtn sureStar">确认</a>

    </div>

</div>

<script>

    $(function () {

        //评分

        var starRating = 0;

        $('.photo span').on('mouseenter',function () {

            var index = $(this).index()+1;

            $(this).prevAll().find('.high').css('z-index',1)

            $(this).find('.high').css('z-index',1)

            $(this).nextAll().find('.high').css('z-index',0)

            $('.starNum').html((index*2).toFixed(1)+'分')

        })

        $('.photo').on('mouseleave',function () {

            $(this).find('.high').css('z-index',0)

            var count = starRating / 2

            if(count == 5) {

                $('.photo span').find('.high').css('z-index',1);

            } else {

                $('.photo span').eq(count).prevAll().find('.high').css('z-index',1);

            }

            $('.starNum').html(starRating.toFixed(1)+'分')

        })

        $('.photo span').on('click',function () {

            var index = $(this).index()+1;

            $(this).prevAll().find('.high').css('z-index',1)

            $(this).find('.high').css('z-index',1)

            starRating = index*2;

            $('.starNum').html(starRating.toFixed(1)+'分');

            alert('评分:'+(starRating.toFixed(1)+'分'))

        })

        //取消评分

        $('.cancleStar').on('click',function () {

            starRating = 0;

            $('.photo span').find('.high').css('z-index',0);

            $('.starNum').html(starRating.toFixed(1)+'分');

        })

        //确定评分

        $('.sureStar').on('click',function () {

            if(starRating===0) {

                alert('最低一颗星!');

            } else {

               alert('评分:'+(starRating.toFixed(1)+'分'))

            }

        })

    })

</script>

</body>

</html>

//样式

#starRating .photo span {

    position: relative;

    display: inline-block;

    width: 44px;

    height: 42px;

    overflow: hidden;

    margin-right: 23px;

    cursor: pointer;

}

#starRating .photo span:last-child {

    margin-right: 0px;

}

#starRating .photo span .nohigh {

    position: absolute;

    width: 44px;

    height: 42px;

    top: 0;

    left: 0;

    background: url("../img/star.png");

}

#starRating .photo span .high {

    position: absolute;

    width: 44px;

    height: 42px;

    top: 0;

    left: 0;

    background: url("../img/star1.png");

}

#starRating .starNum {

    font-size: 26px;

    color: #de4414;

    margin-top: 4px;

    margin-bottom: 10px;

}

#starRating .bottoms {

    height: 54px;

    border-top: 1px solid #d8d8d8;

}

#starRating .photo {

    margin-top: 30px;

}

#starRating .bottoms a {

    margin-bottom: 0;

}

#starRating .bottoms .garyBtn {

    margin-right: 57px!important;

}

#starRating .bottoms a {

    width: 130px;

    height: 35px;

    line-height: 35px;

    border-radius: 3px;

    display: inline-block;

    font-size: 16px;

    transition: all 0.2s linear;

    margin: 16px 0 22px;

    text-align: center;

    cursor: pointer;

}

.garyBtn {

    margin-right: 60px!important;

    background-color: #e1e1e1;

    color: #999999;

}

.blueBtn {

    background-color: #1968b1;

    color: #fff;

}

.blueBtn:hover {

    background: #0e73d0;

}

效果图


单击最后一个五角星


///////////////////////////////////////////////////////////////////


<!doctype html>

<html>

<head>

<meta charset="utf-8">

<title>jQuery案例六五角星评分</title>

<script src="../js/jquery-3.1.1.min.js"></script>

<script>

$(function(){

//全局变量

var score = 0;//成绩初始值

//为所有的li注册mouseenter事件

$('#star li').mouseenter(function(){

var index = $(this).index();//获取当前对象索引

var cur_score = (index+1)*2;//计算分值

$('#score').html(cur_score+"分");//设置分数

//将当前li变成实心的星号

$(this).find('.h').show();

$(this).find('.noh').hide();

//当前元素前面的元素设置成实心星号

$(this).prevAll().find('.h').show();

$(this).prevAll().find('.noh').hide();

//当前元素后面的元素设置成空心星号

$(this).nextAll().find('.h').hide();

$(this).nextAll().find('.noh').show();

});

//为所有li注册click事件

$('#star li').click(function(){

var index = $(this).index();//获取当前对象索引

var cur_score = (index+1)*2;//计算分值

//cur_score局部变量

//score全局变量

score = cur_score;

$('#score').html(score+"分");//设置分数

//将当前li变成实心的星号

//将当前li变成实心的星号

$(this).find('.h').show();

$(this).find('.noh').hide();

//当前元素前面的元素设置成实心星号

$(this).prevAll().find('.h').show();

$(this).prevAll().find('.noh').hide();

//当前元素后面的元素设置成空心星号

$(this).nextAll().find('.h').hide();

$(this).nextAll().find('.noh').show();

});

//为ul注册mouseleave事件

$('#star').mouseleave(function(){

$(this).find('.h').hide();

$(this).find('.noh').show();

var n= score/2;

if(n==5)

{

$(this).find('.h').show();

$(this).find('.noh').hide();

}

else{

$('#star li').eq(n).prevAll().find('.h').show();

$('#star li').eq(n).prevAll().find('.noh').hide();

}

//分值

$('#score').html(score+"分");

});

});

</script>

<style>

*{

padding:0;

margin:0;

}

#star{

width:200px;

height:40px;

font-size:40px;

color:#F69;

cursor:pointer;

margin:20px auto;

}

#star li{

list-style-type:none;

float:left;

width:40px;

height:40px;

text-align:center;

line-height:40px;

position:relative;

}

#star li img{

position:absolute;

top:0;

left:0;

width:40px;

height:40px;

}

#star li img.h{

display:none;

}

#score{

width:200px;

height:40px;

line-height:40px;

text-align:center;

font-size:40px;

margin:0 auto;

}

</style>

</head>


<body>

    <ul id="star">

    <li>

        <img class="h"  src="img4/star1.png">

            <img class="noh" src="img4/star2.png">

        </li>

        <li>

            <img class="h"  src="img4/star1.png">

            <img class="noh" src="img4/star2.png">

        </li>

        <li>

        <img class="h"  src="img4/star1.png">

            <img class="noh"  src="img4/star2.png">

        </li>

        <li>

        <img class="h"  src="img4/star1.png">

            <img class="noh"  src="img4/star2.png">

        </li>

        <li>

        <img class="h"  src="img4/star1.png">

            <img class="noh"  src="img4/star2.png">

        </li>

    </ul>

    <p id="score">0分</p>

</body>

</html>