How do I programmatically set the value of a select box element using JavaScript?

后端 未结 17 1646
轮回少年
轮回少年 2020-11-22 06:33

I have the following HTML

17条回答
  •  南笙
    南笙 (楼主)
    2020-11-22 06:54

    Suppose your form is named form1:

    function selectValue(val)
    {
      var lc = document.form1.leaveCode;
      for (i=0; i<lc.length; i++)
      {
        if (lc.options[i].value == val)
        {
            lc.selectedIndex = i;
            return;
        }
      }
    }
    

提交回复
热议问题