zoukankan      html  css  js  c++  java
  • 实现滑动条与表单中的input中的value交互

      最近在写一个考试系统的项目,遇到一些比较有意思的小知识,在这里分享给大家

      下面是一个滑动条与input中的value值的交互,即滑动条的颜色会跟随给定input的value值实时变化,虽然表单中的range也能实现滑动条的效果,但是range有一定的兼容问题,下面为本人自己写的代码,可直接复制使用,以下为模板,仅供参考

    <!DOCTYPE html>

    <html>

    <head>

    <meta charset="UTF-8">

    <title></title>

    <style type="text/css">

    *{margin: 0;padding: 0;}

    #wrap{

    width:500px;

    height: 500px;

    border: 1px solid black;

    margin: 100px auto;

    }

    form{

    position: relative;

    }

    #board{

    width: 300px;

    height: 10px;

    border: 1px solid black;

    border-radius: 5px;

    position: absolute;

    top: 200px;

    left: 0px;

    list-style: none;

    overflow: hidden;

    }

    #board li{

    float: left;

    height: 10px;

    }

    input{

    margin-top: 30px;

    }

    #hLI{

    background: red;

    }

    #mLI{

    background: green;

    }

    #eLI{

    background: blue;

    }

    </style>

    </head>

    <body>

    <div id="wrap">

    <form action="">

    难<input type="number" id="hard"/><br />

    中<input type="number" id="mid"/><br />

    易<input type="number" id="easy"/><br />

    <ul id="board">

    <li id="hLI"></li>

    <li id="mLI"></li>

    <li id="eLI"></li>

    </ul>

    </form>

    </div>

    </body>

    </html>

    <script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>

    <script type="text/javascript">

    //滑块函数

    function slide(){

    $("#hard").bind('input propertychange', function(){

    $("#hLI").css("width",$("#hard").val()*3);

    });

    $("#mid").bind('input propertychange', function(){

    $("#mLI").css("width",$("#mid").val()*3);

    });

    $("#easy").bind('input propertychange', function(){

    $("#eLI").css("width",$("#easy").val()*3);

    });

    }

    slide();

    </script>

      

  • 相关阅读:
    【NOIP 2003】 加分二叉树
    【POJ 1655】 Balancing Act
    【HDU 3613】Best Reward
    【POJ 3461】 Oulipo
    【POJ 2752】 Seek the Name, Seek the Fame
    【POJ 1961】 Period
    【POJ 2406】 Power Strings
    BZOJ3028 食物(生成函数)
    BZOJ5372 PKUSC2018神仙的游戏(NTT)
    BZOJ4836 二元运算(分治FFT)
  • 原文地址:https://www.cnblogs.com/sunweinan/p/6249975.html
Copyright © 2011-2022 走看看