使用JavaScript中的lodash编写双色球效果


Posted in Javascript onJune 24, 2018

具体代码如下所述:

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
  <style>
    header {
      width: 500px;
      height: 100px;
      margin: 0 auto;
      background-color: red;
      border-radius: 10px;
    }
    header>h1 {
      color: orange;
      text-align: center;
      line-height: 100px;
    }
    li {
      list-style: none;
    }
    input {
      width: 40px;
      height: 30px;
    }
    .change {
      width: 500px;
      height: 400px;
      background-color: burlywood;
      margin: 0 auto;
    }
    .change>p:first-child {
      text-align: center;
      font-size: 24px;
    }
    .change>p:nth-child(2) {
      color: red;
    }
    .change>p:nth-child(4) {
      color: blue;
    }
    #red {
      display: flex;
    }
    #red input {
      margin-right: 20px;
    }
    #star {
      width: 100px;
      height: 50px;
      margin-left: 190px;
    }
    .return {
      color: red;
      font-size: 20px;
      text-align: center;
    }
  </style>
</head>
<body>
  <header>
    <h1>中国福利双色球</h1>
  </header>
  <div class="change">
    <p>请选择号码</p>
    <p>红球(1~33)</p>
    <ul id="red">
      <li id="red1">
        <input type="text" value="">
        <input type="text" value="">
        <input type="text" value="">
        <input type="text" value="">
        <input type="text" value="">
        <input type="text" value="">        
      </li>
    </ul>
    <p>蓝球(1~16)</p>
    <ul id="blue">
      <li>
        <input type="text" value="" id="playblue">
      </li>
    </ul>
    <p>
      <input type="button" value="确定" id="star">
    </p>
    <p>彩票结果为:</p>
    <p class="return"></p>
  </div>
  <script src="./lodash.js"></script>
  <script>
    window.onload = function () {
      let num = [];//创建空数组
      while (true) {
        num.push(_.random(1, 33));//将随机数添加到num中
        num = _.uniq(num)//去重
        if (num.length == 6) {
          break;
        }
      }
      let num1 = [];//蓝球数
      num1.push(_.random(1, 16));
      console.log(num, num1)
      let star = document.getElementById('star');
      let playblue = document.getElementById('playblue');
      let end =document.querySelector('.return');      
      let input = document.querySelectorAll('#red1>input')//得到所有的input
      console.log(input)
      star.onclick = function () {
        //红球
        let play = [];
        _.forEach(input, function (text) {
          let test = text.value-0;//获取输入的值
          play.push(test)
        })
        //蓝球
        let play1=[];
        play1.push(playblue.value-0);
        //判断
        //红球判断
        restu=_.intersection(num,play);
        //蓝球判断
        restu1=_.intersection(num1,play1);
        if(restu.length==6&&restu1.length==0){
          end.innerHTML="恭喜你获得二等奖"
        }else if(restu.length==4||(restu.length==3&&restu1.length==1)){
          end.innerHTML='恭喜你获得五等奖:10元'
        }else if(restu.length==1&&restu1.length==1){
          end.innerHTML='恭喜你获得六等奖:5元'
        }else if(restu.length==0){
          end.innerHTML='未中奖'
        }else if(restu.length==6&&restu1.length==1){
          end.innerHTML="恭喜你获得一等奖500万"
        }else if(restu.length==5&&restu1.length==1){
          end.innerHTML="恭喜你获得三等奖3000元"
        }
      }
    }
  </script>
</body>
</html>

总结

以上所述是小编给大家介绍的使用JavaScript中的lodash编写双色球效果,希望对大家有所帮助,如果大家有任何疑问欢迎给我留言,小编会及时回复大家的!

Javascript 相关文章推荐
新浪刚打开页面出来的全屏广告代码
Apr 02 Javascript
js修改table中Td的值(定义td的单击事件)
Jan 10 Javascript
浅谈javascript 函数属性和方法
Jan 21 Javascript
arguments对象验证函数的参数是否合法
Jun 26 Javascript
jQuery添加和删除输入文本框标签代码
May 20 Javascript
详解Node.js access_token的获取、存储及更新
Jun 20 Javascript
vue-router路由懒加载和权限控制详解
Dec 13 Javascript
JavaScript实现百度搜索框效果
Mar 26 Javascript
Angularjs实现多图片上传预览功能
Jul 18 Javascript
VUE DOM加载后执行自定义事件的方法
Sep 07 Javascript
Vue按时间段查询数据组件使用详解
Aug 21 Javascript
el-table-column 内容不自动换行的解决方法
Aug 14 Vue.js
Vue中$refs的用法详解
Jun 24 #Javascript
JS实现获取word文档内容并输出显示到html页面示例
Jun 23 #Javascript
纯JS实现的读取excel文件内容功能示例【支持所有浏览器】
Jun 23 #Javascript
Vue子组件向父组件通信与父组件调用子组件中的方法
Jun 22 #Javascript
Vue验证码60秒倒计时功能简单实例代码
Jun 22 #Javascript
JS实现图片转换成base64的各种应用场景实例分析
Jun 22 #Javascript
使用vue-infinite-scroll实现无限滚动效果
Jun 22 #Javascript
You might like
使用php清除bom示例
2014/03/03 PHP
php支持断点续传、分块下载的类
2016/05/02 PHP
php判断str字符串是否是xml格式数据的方法示例
2017/07/26 PHP
[原创]PHP正则匹配中英文、数字及下划线的方法【用户名验证】
2017/08/01 PHP
在云虚拟主机部署thinkphp5项目的步骤详解
2017/12/21 PHP
PHP实现负载均衡session共享redis缓存操作示例
2018/08/22 PHP
PHP attributes()函数讲解
2019/02/03 PHP
php实现根据身份证获取精准年龄
2020/02/26 PHP
JS 拼图游戏 面向对象,注释完整。
2009/06/18 Javascript
jQuery+.net实现浏览更多内容(改编php版本)
2013/03/28 Javascript
document.write的几点使用心得
2014/05/14 Javascript
JS 使用for循环遍历子节点查找元素
2014/09/06 Javascript
jQuery实现在列表的首行添加数据
2015/05/19 Javascript
javaScript实现滚动新闻的方法
2015/07/30 Javascript
jQuery过滤特殊字符及JS字符串转为数字
2016/05/26 Javascript
Angular的自定义指令以及实例
2016/12/26 Javascript
Angular 1.x个人使用的经验小结
2017/07/19 Javascript
JS实现基于拖拽改变物体大小的方法
2018/01/23 Javascript
vue初尝试--项目结构(推荐)
2018/01/30 Javascript
修改vue+webpack run build的路径方法
2018/09/01 Javascript
python中使用urllib2获取http请求状态码的代码例子
2014/07/07 Python
Django如何简单快速实现PUT、DELETE方法
2019/07/24 Python
使用批处理脚本自动生成并上传NuGet包(操作方法)
2019/11/19 Python
Python中bisect的使用方法
2019/12/31 Python
python实现从尾到头打印单链表操作示例
2020/02/22 Python
记录一下scrapy中settings的一些配置小结
2020/09/28 Python
linux面试题参考答案(5)
2016/11/05 面试题
优秀学生干部个人的自我评价
2013/10/04 职场文书
教师求职信范文分享
2013/12/27 职场文书
会计大学生职业生涯规划书范文
2014/01/13 职场文书
捐款倡议书格式范文
2014/05/14 职场文书
2014年图书馆工作总结
2014/11/25 职场文书
2014年政府采购工作总结
2014/12/09 职场文书
司机岗位职责范本
2015/04/10 职场文书
天气温馨提示语
2015/07/14 职场文书
三年级作文之趣事作文
2019/11/04 职场文书