简体   繁体   中英

How to swap options between two <select> list

I'm new to Javascript, and I want to swap these two options when the exchange button is clicked Page

在此处输入图片说明

HTML

<div class="form-group col-4">
    <button type="button" class="btn bg-dark text-white" id="exchange" style="margin-top: 23px; margin-left: 10px;"> 
          <i class="fa fa-exchange" aria-hidden="true"></i>
    </button>
</div>

Javascript

function swap() {
  let inp = document.getElementById("inputCurrency").value;
  let out = document.getElementById("outputCurrency").value;
  document.getElementById("inputCurrency").value = out;
  document.getElementById("outputCurrency").value = inp;
}

let amountInput = document.getElementById("amount");

let inputCurrency = document.getElementById("inputCurrency");
let outputCurrency = document.getElementById("outputCurrency");

let convertButton = document.getElementById('convertButton');
convertButton.addEventListener("click",convertCurrency);

let exchangeButton = document.getElementById("exchange");
exchangeButton.addEventListener("click",swap());

I'm new to Javascript, and I want to swap these two options when the exchange button is clicked Page

在此处输入图片说明

HTML

<div class="form-group col-4">
    <button type="button" class="btn bg-dark text-white" id="exchange" style="margin-top: 23px; margin-left: 10px;"> 
          <i class="fa fa-exchange" aria-hidden="true"></i>
    </button>
</div>

Javascript

function swap() {
  let inp = document.getElementById("inputCurrency").value;
  let out = document.getElementById("outputCurrency").value;
  document.getElementById("inputCurrency").value = out;
  document.getElementById("outputCurrency").value = inp;
}

let amountInput = document.getElementById("amount");

let inputCurrency = document.getElementById("inputCurrency");
let outputCurrency = document.getElementById("outputCurrency");

let convertButton = document.getElementById('convertButton');
convertButton.addEventListener("click",convertCurrency);

let exchangeButton = document.getElementById("exchange");
exchangeButton.addEventListener("click",swap());

I'm new to Javascript, and I want to swap these two options when the exchange button is clicked Page

在此处输入图片说明

HTML

<div class="form-group col-4">
    <button type="button" class="btn bg-dark text-white" id="exchange" style="margin-top: 23px; margin-left: 10px;"> 
          <i class="fa fa-exchange" aria-hidden="true"></i>
    </button>
</div>

Javascript

function swap() {
  let inp = document.getElementById("inputCurrency").value;
  let out = document.getElementById("outputCurrency").value;
  document.getElementById("inputCurrency").value = out;
  document.getElementById("outputCurrency").value = inp;
}

let amountInput = document.getElementById("amount");

let inputCurrency = document.getElementById("inputCurrency");
let outputCurrency = document.getElementById("outputCurrency");

let convertButton = document.getElementById('convertButton');
convertButton.addEventListener("click",convertCurrency);

let exchangeButton = document.getElementById("exchange");
exchangeButton.addEventListener("click",swap());

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM