select 동작 선택 자 바스 크 립 트 추가, 삭제

4672 단어 JavaScript
//     
    function addItem()
    {
        var myMember = document.getElementById("myMember");
        var otherMember = document.getElementById("otherMember");
          for (var i=0;i<myMember.options.length;i++){
              
              if (myMember.options[i].selected == true){
                  if(!isExitItem(myMember.options[i].value)){
                       $("#otherMember").append("<option value='" + myMember.options[i].value + "'>" +myMember.options[i].text + "</option");  
                }
               }
          }
    }
    //     
    function addAll()
    {
        var myMember = document.getElementById("myMember");
        var otherMember = document.getElementById("otherMember");
        for (var i=0;i<myMember.options.length;i++){
            if(!isExitItem(myMember.options[i].value)){
                  $("#otherMember").append("<option value='" + myMember.options[i].value + "'>" +myMember.options[i].text + "</option");  
            }
          }
    }
    //     
    function removeAll()
    {
        var otherMember = document.getElementById("otherMember");
        var length = otherMember.options.length; 
        for(var i=length-1;i>=0;i--){ 
            otherMember.options.remove(i); 
        } 
    }
    //       
    function isExitItem(val)
    {
        var flag=false;
        var otherMember = document.getElementById("otherMember");
        for (var i=0;i<otherMember.options.length;i++){
            if (otherMember.options[i].value == val){
                flag=true;
                  break;
               }
          }
          return flag;
    }
    //     
    function removeItem()
    {
        var otherMember = document.getElementById("otherMember");
          for (var i=0;i<otherMember.options.length;i++){
            if (otherMember.options[i].selected == true){
                  $(otherMember.options[i]).remove();
               }
          }
    }


.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }

좋은 웹페이지 즐겨찾기