0
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

JavaScriptで自動計算

Posted at

自動計算機能の実装

自分用のメモです〜
正解かどうかは分かりません!!
が、ひとまず動いたので残しておきます。


function calc (){
  const itemPrice = document.getElementById("item-price");
  itemPrice.addEventListener("keyup",()=>{
//取得した要素が入力されたら(keyup)イベント発火
    tax = parseInt(itemPrice.value * 0.1);
    const addTax = document.getElementById("add-tax-price");
    addTax.innerHTML = `${tax}円`
//taxはアイテムの値段.valudの10%を小数点以下切り捨て
//表示させる要素を取得して、innnerHTMLで上書き

    prof = (itemPrice.value) - (tax)
    const priceContent = document.getElementById("profit");
    priceContent.innerHTML = prof
  })
}

window.addEventListener('load',calc);


めちゃくちゃ頭抱えて悩んでたけど、めちゃくちゃ基礎でした。。
精進します。

以上

0
2
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?