Home >Web Front-end >JS Tutorial >js automatically finds the select drop-down menu and selects it (sample code)_javascript skills

js automatically finds the select drop-down menu and selects it (sample code)_javascript skills

WBOY
WBOYOriginal
2016-05-16 16:58:221218browse
复制代码 代码如下:

function find_select(name)
{
 var select = document.getElementsByName(name);
 var find_str = document.getElementById('to_find_str').value;
 if(select)
 {
  select = select[0];
  var child = select.childNodes;
  var can=false,text='',len=child.length,is_end=true;
  for(var i=0;i  {
   if(can)
   {
    text = child[i].text;
    if( text &&
     text.indexOf(find_str)!=-1)
    {
     //console.log(text);
     child[i].selected = true;
     var v = child[i].value;
     select.value = v;
     select.onchange(v);
     is_end = false;
     break;
    }
   }
   if(child[i].selected)
    can = true;
  }
  if(is_end)
   alert('已没有匹配内容');
 }
}

复制代码 代码如下:


         
         
   
     --
         
     
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn