choices js无法使用es5语法在2个输入之间交换select的值

时间:2018-12-12 07:25:10

标签: javascript

我想在2个输入选择之间进行交换,但是单击交换按钮后值不会更新。

这是我的代码:

pug

select.form-control.form-control-lg#originInput
    option(placeholder) From
    option Jakarta - CGK

  select.form-control.form-control-lg#destinatnionInput
    option(placeholder) To
    option Yogyakarta - JOG

js

var originInput = document.getElementById("originInput")
  var destinationInput = document.getElementById("destinationInput")

  // swap button
  var swap = document.getElementById("swapButton")
  swap.addEventListener("click", function() {
    destinationInput.value = [originInput.value, originInput.value = 
  destinationInput.value][0]
  })

但值不交换,只能获取空值。 因此,我尝试更改为es6语法,并且可以使用。

swap.addEventListener("click", function() {
  [destinationInput, originInput] = [originInput, destinationInput]
})

我不知道为什么它不能在ES5上运行.. 以及如何更新所选值的视图?

0 个答案:

没有答案