Skip to content

Instantly share code, notes, and snippets.

@erySanDriver
Last active August 21, 2018 14:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save erySanDriver/95b1381f501d86d28d00bcf38249ed57 to your computer and use it in GitHub Desktop.
Save erySanDriver/95b1381f501d86d28d00bcf38249ed57 to your computer and use it in GitHub Desktop.
<script>
($function () {
var $test;     // 各テキストボックスに入る数値を順番に格納する配列
var $result; // 計算結果を格納する変数
// 同じクラス名の値をeachで取得する
$('.test').each(function (i) {
// 1.テキストボックスへの入力をトリガーにする
$(this).keyup(function () {
// それぞれのテキストボックスに入った値を取得
$test[i] = ParseInt($(this).val());
});
// 配列に格納したそれぞれのテキストボックスの値で計算
        for (var $val of $test) {
$result += $val;
}
$('.caluculate').text($result);
});
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment