现在的位置: 首页 > 综合 > 正文

常用的js与select的数据项的移入移除

2012年10月21日 ⁄ 综合 ⁄ 共 1281字 ⁄ 字号 评论关闭

   <script type="text/javascript">
    //移入
     function Cike()
   {
   var objDrpCick=document.getElementById("DropCompant3");
   var objValue=objDrpCick.options[objDrpCick.selectedIndex].text;
   var objType=document.getElementById("ProTypes");
   if(objValue=="请选择")
   {
     alert("请您选择行业的子类别!");
     return false;
   }
   else
   {   
     if(objType.length!="0")
     {
      alert(objType.length);
      var len=objType.length;
      for(var i=0;i<len;i++)
      {
      
       if(objType.options[i].value==objValue) //注意技巧
       {
        alert("已经存在,请重新选择!");
        return false;
       }
      }  
          var opt=new Option(objValue,objValue);
          objType.options.add(opt);
          return true;
     
      }
     else
     {
  
      objType.options.add(new Option(objValue,objValue));
     }
     return true;
     }
   }
   //移除
 function RemoveOut()
 {
  var lists=document.getElementById("ProTypes");
  var len=lists.length;
  if(len=="0")
  {
   alert("对不起,没有可移除的项!");
   return false;
  }
  else
  {
  var vs=lists.value;
   if(vs=="")
   {
    alert("对不起,您还没选择要删除的项目!");
   }
   else
   {
    for(var i = lists.options.length - 1 ; i >= 0 ; i--)
    {
     if(lists.options[i].selected)
     {
     lists.remove(i);
    }
    }
    }
  }
 }
 function TestInfo()
 {
    var objType=document.getElementById("ProTypes");
    for(var i=0; i<objType.length; i++)
    {
      alert(objType.options[i].value);
    }
 }
    </script>

抱歉!评论已关闭.