“Pilih HTML” Kode Jawaban

Pilih HTML

<select class="form-control">
  <option>1</option>
  <option>2</option>
  <option>3</option>
  <option>4</option>
  <option>5</option>
</select>
Felipebros

Pilih HTML

const showSelect = function(){
  text = select.options[select.selectedIndex].textContent;
  label.innerHTML = textVisible == select.value ?
  `Opción seleccionada ${text} <br> NO tiene atributo "value" asignado` : 
  `Opción seleccionada "${text}" <br> SI tiene atributo "value" igual a "${select.value}"`; 
};

const findValue = function(value){
  result = -1;
  let index = 0;
  while(!result & index < select.options.length){
    if(option.value == value) result = index;
    index++;
  }
  return result;
}

const findText = function(value){
  result = -1;
  let index = 0;
  while(!result & index < select.options.length){
    if(option.textContaint == value) result = index;
    index++;
  }
  return result;
}

const removeValue = function(value){
  result = false;
  index = findValue(value);
  if(index){
    select.remove(index);
    result = true;
  };
  return result;  
}

const removeText = function(value){
  result = false;
  index = findText(value);
  if(index){
    select.remove(index);
    result = true;
  };
  return result;  
};

showSelect();

select.addEventListener('change', function(){
  showSelect();
});
Talented Tapir

Jawaban yang mirip dengan “Pilih HTML”

Pertanyaan yang mirip dengan “Pilih HTML”

Lebih banyak jawaban terkait untuk “Pilih HTML” di HTML

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya