js the basic operation of the select (MEMO)

1. Increase option:

  function addoption (pa0, pa1, pa2) // select control, the text display option, the option value value

         {
             var option = document.createElement("option");
             option.appendChild(document.createTextNode(pa1));
            option.setAttribute("value",pa2);
            pa0.appendChild(option);
      }

2. Get the selected option:

  var obj = document.getElementByIdx_x(”testSelect”); //定位id

  var index = obj.selectedIndex; // Select Index

  var text = obj.options [index] .text; // selected text

  var value = obj.options [index] .value; // selected value

3. Delete the selected option

  var obj=document.getElementById('mySelect');

  var index=obj.selectedIndex;

  obj.options.remove(index);


4. Empty select

  mySelect.options.length=0;

Reproduced in: https: //my.oschina.net/secyaher/blog/274424

Guess you like

Origin blog.csdn.net/weixin_33716941/article/details/91966905