Git Product home page Git Product logo

select's Introduction

select

This is a compilation of their own select, simple and easy

  • oBox:模拟的选择框
  • aSpan:模拟的options 每个选项
  • oI:选择框右边的图标,例如下拉三角
  • bNameb:下拉三角默认样式className
  • aName:下拉三角点击后的样式className
  • optName:每一项option的样式className
  • addEvent,removeEvent:辅助函数

####//插件源码

function select(oBox,aSpan,oI,bNameb,aName,optName)
{
    function addEvent(obj, sEv, fn)
    {
        if (obj.addEventListener)
        {
            obj.addEventListener(sEv, fn, false);
        }
        else
        {
            obj.attachEvent('on'+sEv, fn);
        }
    }

    function removeEvent(obj, sEv, fnName)
    {
        if (obj.removeEventListener)
        {
            obj.removeEventListener(sEv, fnName, false);
        }
        else
        {
            obj.detachEvent('on'+sEv, fnName);
        }
    }
    oBox.onclick=function(){
        //下拉三角的样式
        oI.className=bNameb;
        for(var i=0;i<aSpan.length;i++)
        {
            aSpan[i].style.display='block';
            (function(index){
                function selectOver(){
                    for(var i=0;i<aSpan.length;i++)
                    {
                        aSpan[i].className='';
                    }
                    //options选中之后的样式
                    aSpan[index].className=optName;
                }
                function selectClick(){
                    //下拉三角的样式
                    oI.className=aName;
                    for(var i=0;i<aSpan.length;i++)
                    {
                        aSpan[i].style.display='none';
                        aSpan[i].setAttribute('data-con',aSpan[i].innerHTML);
                        oBox.innerHTML=aSpan[index].getAttribute('data-con');
                    }
                    removeEvent(aSpan[i],'mouseover',selectOver);
                    removeEvent(aSpan[i],'click',selectClick);
                }
                addEvent(aSpan[i],'mouseover',selectOver);
                addEvent(aSpan[i],'click',selectClick);
            })(i);
        }
    };

} ####//使用 直接调用即可

select's People

Contributors

zhangdanqing avatar

Stargazers

 avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.