bugfix> jquery > 投稿

次のように入力のあるアイテムで構成されるリストを作成しました。

jqueryでは、いくつかの関数を作成しました( Formula を変更します Balance によるテキスト値、 Balance の形式を変更入力し、リスト項目を削除します)。最初はすべての機能が動作しますが、 Add Item + をクリックするとそして、それが機能しない新しいアイテムリストで関数をトリガーしようとします。

なぜこれが起こったのか分かりません。どんな助けも感謝します! :)

var tempMulti;
$(document).ready(function() {
  resizeMultiPadding();
  tempMulti = $(".multi-list").html();
});
$(window).resize(function() {
  resizeMultiPadding();
});
function resizeMultiPadding() {
  if ($(window).width() >= 576) {
    var padding =  $(window).width() * 0.04;
    $(".multi-col").css({"padding-right": padding + "px"});
    $(".multi-col:last-child").css({"padding-right": "0"});
    $(".multi-list-each-delete").html("<i class='fas fa-trash'></i>");
  }
  else {
    $(".multi-list-each-delete").html("<a class='button footer-btn text-btn'><span><i class='fas fa-trash'></i>Delete</span></a>");
  }
}
$(".spinner-up").click(function() {
  var amount = parseInt($(this).parent().prev().prev().val()) || 0;
  amount += 1;
  $(this).parent().prev().prev().val(amount);
});
$(".spinner-down").click(function() {
  var value = $(this).parent().prev().prev().val();
  var amount = parseInt(value) || 0;
  if (amount > 0) {
    amount -= 1; 
  }
  $(this).parent().prev().prev().val(amount);
});
(function($, undefined) {
  "use strict";
  $(function() {
    var $form = $("#form-amount-input, .balance-group");
    var $input = $form.find("input");
    $input.on("keyup", function(event) {
    var selection = window.getSelection().toString();
    if (selection !== "") {
      return;
    }
    if ($.inArray(event.keyCode, [38,40,37,39]) !== -1) {
      return;
    }
    var $this = $(this);
    var input = $this.val();
    input = input.replace(/[\D\s\._\-]+/g, "");
    input = input ? parseInt(input, 10) : 0;
    var formatted = input.toLocaleString("en-US");
    $this.val(formatted);
    $this.parent().parent().parent().find(".panel-data-value").text("Formula + " + formatted + ".00");
    if (formatted == "0") {
      $this.parent().parent().parent().find(".panel-data-value").text("Formula");
    }
  });
  });
})(jQuery);
$(".add-multi").click(function() {
  $(".multi-list").prepend(tempMulti);
});
$(".multi-list-each-delete").click(function() {
  $(this).parent().hide();
});

.form {
  margin-bottom: 40px;
  margin: 0 auto;
  width: 768px;
  font-family: 'Open Sans', sans-serif;
}
h1 {
 font-size: 13px;
  text-transform: uppercase;
  color: #0099ff;
  margin-bottom: 24px;
}
.input-text {
  height: 34px;
  border: solid 1px #c4c4c4;
  width: 366px;
  font-size: 13px;
  padding: 0 12px 0 12px;
  margin-bottom: 24px;
  color: #333;
  border-radius: 0;
  background-color: transparent;
}
.input-text:focus {
  border: solid 1px #00c983 !important; 
}
::placeholder {
  color: #c4c4c4; 
  font-size: 13px;
  text-align: left !important;
}
.form-input-label {
  display: block;
  font-size: 12px;
  font-weight: 700;
  margin-bottom: 8px;
  color: #333;
}
.input-disabled {
  background-color: #eee; 
}
.form-unit {
  position: relative;
  vertical-align: top;
}
.input-select-btn {
  width: 34px;
  height: 34px;
  position: absolute;
  top: 25px;
  right: 0;
  text-align: center;
  line-height: 34px;
  cursor: pointer;
  z-index: -999;
}
.dropdown-btn-wrapper-clear {
  border-left: solid 1px #c4c4c4; 
}
.input-select-btn i {
  color: #666 !important; 
}
.on-disabled-btn {
  border: solid 1px #c4c4c4;
  background-color: #fff;
}
.input-select-btn i {
  font-size: 12px;
  color: #333;
}
.form-row {
  display: block;
  width: 100%;
  margin: 0 !important;
}
.form-divided {
  display: inline-block;
}
.form-divided-left {
  margin-right: 32px;
}
.btn-label {
  background-color: #eee; 
}
.spinner-group {
  position: absolute; 
  width: 16px;
  height: 26px;
  top: 4px;
  right: 44px;
}
.spinner-up,
.spinner-down {
  height: 13px;
  line-height: 13px;
  display: block;
}
.spinner-down {
  top: 12px !important; 
}
.spinner-up i,
.spinner-down i {
  line-height: 13px;
}
input[type=number]::-webkit-inner-spin-button, 
input[type=number]::-webkit-outer-spin-button { 
  -webkit-appearance: none; 
  margin: 0; 
}
.input-with-spinner {
  text-align: right;
  padding-right: 32px; 
}
#amount-input {
  width: 100% !important; 
}
.amount-spinner-group {
  right: 10px; 
}
.add-multi {
  height: 40px;
  width: 100%;
  text-align: center;
  line-height: 40px;
  border: dashed 2px #eaeaea;
  font-size: 13px;
  cursor: pointer;
  margin-bottom: 8px;
}
.add-multi:hover {
  background-color: #f8f8f8; 
}
.add-multi i {
  font-size: 10px; 
  transform: translateY(-1px);
  margin-left: 4px;
}
.multi-list-each {
  background-color: #f8f8f8;
  display: block;
  width: 100%;
  padding: 16px 24px 12px;
  position: relative;
  margin-bottom: 8px;
}
.multi-list-each input {
  background-color: #fff; 
}
.multi-form-group {
  position: relative;
  width: 100%;
}
.multi-form-group input { 
  width: 100%;
  margin-bottom: 0;
}
.spinner-group-year {
  right: 2px; 
}
#balance-currency {
  position: absolute;
  z-index: 99;
  top: 0;
  left: 0;
  color: #333;
  text-decoration: none;
}
.multi-col {
  display: inline-block;
  vertical-align: top;
  padding-right: 16px;
  padding-left: 16px;
}
.multi-col:first-child {
  padding-left: 0;
}
.multi-col:last-child {
  padding-right: 0;
}
.multi-col input {
  margin-bottom: 0; 
}
.multi-list-each-delete {
  position: absolute; 
  right: 24px;
  top: 50%;
  transform: translateY(-50%);
}
.multi-list-each-delete i {
  font-size: 12px; 
}
@media (max-width: 767px) and (min-width: 576px) {
  .form {
    padding-left: 16px;
    padding-right: 16px;
    width: 100%;
  }
  
  .form-divided-left {
    margin-right: 24px;
  }
  
  .form-divided {
    width: calc(50% - 14px);
  }
  
  .input-text,
  textarea {
    display: inline-block;
    width: 100%;
  }
  
  .input-select-btn {
    right: 0;
  }
  
  .labeled-row {
    display: block;
    width: 100%;
  }
  
  .form-unit .select2-container, .form-unit .select2-selection {
      width: 100% !important;
  }
}
@media (max-width: 575px) {
  .form {
    padding-left: 16px;
    padding-right: 16px;
    width: 100%;
  }
  
  .form-divided {
    display: block; 
    width: 100%;
  }
  
  .form-divided-left {
    margin-right: 0; 
  }
  
  .input-text,
  textarea {
    display: inline-block;
    width: 100%;
  }
  
  .labeled-row {
    display: block;
    width: 100%;
  }
  .form-unit .select2-container, .form-unit .select2-selection {
      width: 100% !important;
  }
  
  .multi-col {
    margin-bottom: 16px; 
    padding-left: 0;
    padding-right: 0 !important;
  }
  
  .multi-list-each-delete {
    bottom: 8px;
    top: auto;
    left: 50%;
    transform: translateX(-50%);
    text-align: center;
    color: #999;
  }
  
  .multi-list-each-delete .button:hover {
    background-color: #eee;
    color: #999;
    text-decoration: none;
  }
}

<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.0.11/css/all.css" integrity="sha384-p2jx59pefphTFIpeqCcISO9MdVfIm4pNnsL08A6v5vaQc4owkQqxMV8kg4Yvhaw/" crossorigin="anonymous">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<link href="https://fonts.googleapis.com/css?family=Open+Sans:400,400i,700,700i" rel="stylesheet">
<div class="form">
  <div class="form-row">
    <div class="form-unit">
      <div class="multi-attribute">
        <label class="form-input-label">Multi-Attributes Input</label>
        <div class="add-multi">Add item <i class="fas fa-plus"></i></div>
        <ul class="multi-list">
          <li class="multi-list-each">
            <div class="col-33 multi-col">
              <label class="form-input-label">Year</label>
              <div class="multi-form-group">
                <input class="year-input input-text input-with-spinner" type="number" min="0" placeholder="Add year">
                <a />
                <div class="spinner-group spinner-group-year">
                  <a class="spinner-up"><i class="fas fa-caret-up"></i></a>
                  <a class="spinner-down"><i class="fas fa-caret-down"></i></a>
                </div>
              </div>
            </div>
            <div class="col-33 multi-col">
              <label class="form-input-label">Balance Increase</label>
              <div class="balance-group multi-form-group">
                <input class="balance-input input-text input-with-spinner" type="text" placeholder="Add balance">
                <a />
                <div class="spinner-group spinner-group-year">
                  <a class="spinner-up"><i class="fas fa-caret-up"></i></a>
                  <a class="spinner-down"><i class="fas fa-caret-down"></i></a>
                </div>
              </div>
            </div>
            <div class="col-33 multi-col">
              <div class="panel-data panel-data-vertical">
                <div class="panel-data-label">
                  Total Balance
                </div>
                <div class="panel-data-value">
                  Formula
                </div>
              </div>
            </div>
            <div class="multi-list-each-delete"><i class="fas fa-trash"></i></div>
          </li>
        </ul>
      </div>
    </div>
  </div>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.4.1/js/bootstrap-datepicker.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.4.1/css/bootstrap-datepicker3.css"/>
<link href="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.1/css/select2.min.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.1/js/select2.min.js"></script>

回答 4 件
  • jqueryは $(document).ready にロードされたDOMで動作します 。新しい要素をターゲットにするには、次のような関数を作成する必要があります。

    $(document).on('handler', '#my-new-element-id', function()
    {
        alert('clicked the new guy')
    })
    
    

  • $(".spinner-up") を変更   $(document).on("click",".spinner-up",function() {

    他のいくつかの要素についても同様です。

    作業デモ

    var tempMulti;
    $(document).ready(function() {
      resizeMultiPadding();
      tempMulti = $(".multi-list").html();
    });
    $(window).resize(function() {
      resizeMultiPadding();
    });
    function resizeMultiPadding() {
      if ($(window).width() >= 576) {
        var padding =  $(window).width() * 0.04;
        $(".multi-col").css({"padding-right": padding + "px"});
        $(".multi-col:last-child").css({"padding-right": "0"});
        $(".multi-list-each-delete").html("<i class='fas fa-trash'></i>");
      }
      else {
        $(".multi-list-each-delete").html("<a class='button footer-btn text-btn'><span><i class='fas fa-trash'></i>Delete</span></a>");
      }
    }
    $(document).on("click",".spinner-up",function() {
      var amount = parseInt($(this).parent().prev().prev().val()) || 0;
      amount += 1;
      $(this).parent().prev().prev().val(amount);
    });
    $(document).on("click",".spinner-down",function() {
      var value = $(this).parent().prev().prev().val();
      var amount = parseInt(value) || 0;
      if (amount > 0) {
        amount -= 1; 
      }
      $(this).parent().prev().prev().val(amount);
    });
    (function($, undefined) {
      "use strict";
      $(function() {
        var $form = $("#form-amount-input, .balance-group");
        var $input = $form.find("input");
        $input.on("keyup", function(event) {
        var selection = window.getSelection().toString();
        if (selection !== "") {
          return;
        }
        if ($.inArray(event.keyCode, [38,40,37,39]) !== -1) {
          return;
        }
        var $this = $(this);
        var input = $this.val();
        input = input.replace(/[\D\s\._\-]+/g, "");
        input = input ? parseInt(input, 10) : 0;
        var formatted = input.toLocaleString("en-US");
        $this.val(formatted);
        $this.parent().parent().parent().find(".panel-data-value").text("Formula + " + formatted + ".00");
        if (formatted == "0") {
          $this.parent().parent().parent().find(".panel-data-value").text("Formula");
        }
      });
      });
    })(jQuery);
    $(document).on("click",".add-multi",function() {
      $(".multi-list").prepend(tempMulti);
    });
    $(document).on("click",".multi-list-each-delete",function() {
      $(this).parent().hide();
    });
    
    
    .form {
      margin-bottom: 40px;
      margin: 0 auto;
      width: 768px;
      font-family: 'Open Sans', sans-serif;
    }
    h1 {
     font-size: 13px;
      text-transform: uppercase;
      color: #0099ff;
      margin-bottom: 24px;
    }
    .input-text {
      height: 34px;
      border: solid 1px #c4c4c4;
      width: 366px;
      font-size: 13px;
      padding: 0 12px 0 12px;
      margin-bottom: 24px;
      color: #333;
      border-radius: 0;
      background-color: transparent;
    }
    .input-text:focus {
      border: solid 1px #00c983 !important; 
    }
    ::placeholder {
      color: #c4c4c4; 
      font-size: 13px;
      text-align: left !important;
    }
    .form-input-label {
      display: block;
      font-size: 12px;
      font-weight: 700;
      margin-bottom: 8px;
      color: #333;
    }
    .input-disabled {
      background-color: #eee; 
    }
    .form-unit {
      position: relative;
      vertical-align: top;
    }
    .input-select-btn {
      width: 34px;
      height: 34px;
      position: absolute;
      top: 25px;
      right: 0;
      text-align: center;
      line-height: 34px;
      cursor: pointer;
      z-index: -999;
    }
    .dropdown-btn-wrapper-clear {
      border-left: solid 1px #c4c4c4; 
    }
    .input-select-btn i {
      color: #666 !important; 
    }
    .on-disabled-btn {
      border: solid 1px #c4c4c4;
      background-color: #fff;
    }
    .input-select-btn i {
      font-size: 12px;
      color: #333;
    }
    .form-row {
      display: block;
      width: 100%;
      margin: 0 !important;
    }
    .form-divided {
      display: inline-block;
    }
    .form-divided-left {
      margin-right: 32px;
    }
    .btn-label {
      background-color: #eee; 
    }
    .spinner-group {
      position: absolute; 
      width: 16px;
      height: 26px;
      top: 4px;
      right: 44px;
    }
    .spinner-up,
    .spinner-down {
      height: 13px;
      line-height: 13px;
      display: block;
    }
    .spinner-down {
      top: 12px !important; 
    }
    .spinner-up i,
    .spinner-down i {
      line-height: 13px;
    }
    input[type=number]::-webkit-inner-spin-button, 
    input[type=number]::-webkit-outer-spin-button { 
      -webkit-appearance: none; 
      margin: 0; 
    }
    .input-with-spinner {
      text-align: right;
      padding-right: 32px; 
    }
    #amount-input {
      width: 100% !important; 
    }
    .amount-spinner-group {
      right: 10px; 
    }
    .add-multi {
      height: 40px;
      width: 100%;
      text-align: center;
      line-height: 40px;
      border: dashed 2px #eaeaea;
      font-size: 13px;
      cursor: pointer;
      margin-bottom: 8px;
    }
    .add-multi:hover {
      background-color: #f8f8f8; 
    }
    .add-multi i {
      font-size: 10px; 
      transform: translateY(-1px);
      margin-left: 4px;
    }
    .multi-list-each {
      background-color: #f8f8f8;
      display: block;
      width: 100%;
      padding: 16px 24px 12px;
      position: relative;
      margin-bottom: 8px;
    }
    .multi-list-each input {
      background-color: #fff; 
    }
    .multi-form-group {
      position: relative;
      width: 100%;
    }
    .multi-form-group input { 
      width: 100%;
      margin-bottom: 0;
    }
    .spinner-group-year {
      right: 2px; 
    }
    #balance-currency {
      position: absolute;
      z-index: 99;
      top: 0;
      left: 0;
      color: #333;
      text-decoration: none;
    }
    .multi-col {
      display: inline-block;
      vertical-align: top;
      padding-right: 16px;
      padding-left: 16px;
    }
    .multi-col:first-child {
      padding-left: 0;
    }
    .multi-col:last-child {
      padding-right: 0;
    }
    .multi-col input {
      margin-bottom: 0; 
    }
    .multi-list-each-delete {
      position: absolute; 
      right: 24px;
      top: 50%;
      transform: translateY(-50%);
    }
    .multi-list-each-delete i {
      font-size: 12px; 
    }
    @media (max-width: 767px) and (min-width: 576px) {
      .form {
        padding-left: 16px;
        padding-right: 16px;
        width: 100%;
      }
      
      .form-divided-left {
        margin-right: 24px;
      }
      
      .form-divided {
        width: calc(50% - 14px);
      }
      
      .input-text,
      textarea {
        display: inline-block;
        width: 100%;
      }
      
      .input-select-btn {
        right: 0;
      }
      
      .labeled-row {
        display: block;
        width: 100%;
      }
      
      .form-unit .select2-container, .form-unit .select2-selection {
          width: 100% !important;
      }
    }
    @media (max-width: 575px) {
      .form {
        padding-left: 16px;
        padding-right: 16px;
        width: 100%;
      }
      
      .form-divided {
        display: block; 
        width: 100%;
      }
      
      .form-divided-left {
        margin-right: 0; 
      }
      
      .input-text,
      textarea {
        display: inline-block;
        width: 100%;
      }
      
      .labeled-row {
        display: block;
        width: 100%;
      }
      .form-unit .select2-container, .form-unit .select2-selection {
          width: 100% !important;
      }
      
      .multi-col {
        margin-bottom: 16px; 
        padding-left: 0;
        padding-right: 0 !important;
      }
      
      .multi-list-each-delete {
        bottom: 8px;
        top: auto;
        left: 50%;
        transform: translateX(-50%);
        text-align: center;
        color: #999;
      }
      
      .multi-list-each-delete .button:hover {
        background-color: #eee;
        color: #999;
        text-decoration: none;
      }
    }
    
    
    <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.0.11/css/all.css" integrity="sha384-p2jx59pefphTFIpeqCcISO9MdVfIm4pNnsL08A6v5vaQc4owkQqxMV8kg4Yvhaw/" crossorigin="anonymous">
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
    <link href="https://fonts.googleapis.com/css?family=Open+Sans:400,400i,700,700i" rel="stylesheet">
    <div class="form">
      <div class="form-row">
        <div class="form-unit">
          <div class="multi-attribute">
            <label class="form-input-label">Multi-Attributes Input</label>
            <div class="add-multi">Add item <i class="fas fa-plus"></i></div>
            <ul class="multi-list">
              <li class="multi-list-each">
                <div class="col-33 multi-col">
                  <label class="form-input-label">Year</label>
                  <div class="multi-form-group">
                    <input class="year-input input-text input-with-spinner" type="number" min="0" placeholder="Add year">
                    <a />
                    <div class="spinner-group spinner-group-year">
                      <a class="spinner-up"><i class="fas fa-caret-up"></i></a>
                      <a class="spinner-down"><i class="fas fa-caret-down"></i></a>
                    </div>
                  </div>
                </div>
                <div class="col-33 multi-col">
                  <label class="form-input-label">Balance Increase</label>
                  <div class="balance-group multi-form-group">
                    <input class="balance-input input-text input-with-spinner" type="text" placeholder="Add balance">
                    <a />
                    <div class="spinner-group spinner-group-year">
                      <a class="spinner-up"><i class="fas fa-caret-up"></i></a>
                      <a class="spinner-down"><i class="fas fa-caret-down"></i></a>
                    </div>
                  </div>
                </div>
                <div class="col-33 multi-col">
                  <div class="panel-data panel-data-vertical">
                    <div class="panel-data-label">
                      Total Balance
                    </div>
                    <div class="panel-data-value">
                      Formula
                    </div>
                  </div>
                </div>
                <div class="multi-list-each-delete"><i class="fas fa-trash"></i></div>
              </li>
            </ul>
          </div>
        </div>
      </div>
    </div>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
    <script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
    <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.4.1/js/bootstrap-datepicker.min.js"></script>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.4.1/css/bootstrap-datepicker3.css"/>
    <link href="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.1/css/select2.min.css" rel="stylesheet" />
    <script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.1/js/select2.min.js"></script>
    
    

  • onkeyupイベントをこの行に置き換えます...

    $(document).on("keyup","#form-amount-input, .balance-group input",
    
    

    イベントが設定された後に要素がアタッチされた場合でも、それを起動するライブイベントを作成する必要があります。

    var tempMulti;
    $(document).ready(function() {
      resizeMultiPadding();
      tempMulti = $(".multi-list").html();
    });
    $(window).resize(function() {
      resizeMultiPadding();
    });
    function resizeMultiPadding() {
      if ($(window).width() >= 576) {
        var padding =  $(window).width() * 0.04;
        $(".multi-col").css({"padding-right": padding + "px"});
        $(".multi-col:last-child").css({"padding-right": "0"});
        $(".multi-list-each-delete").html("<i class='fas fa-trash'></i>");
      }
      else {
        $(".multi-list-each-delete").html("<a class='button footer-btn text-btn'><span><i class='fas fa-trash'></i>Delete</span></a>");
      }
    }
    $(".spinner-up").click(function() {
      var amount = parseInt($(this).parent().prev().prev().val()) || 0;
      amount += 1;
      $(this).parent().prev().prev().val(amount);
    });
    $(".spinner-down").click(function() {
      var value = $(this).parent().prev().prev().val();
      var amount = parseInt(value) || 0;
      if (amount > 0) {
        amount -= 1; 
      }
      $(this).parent().prev().prev().val(amount);
    });
    (function($, undefined) {
      "use strict";
      $(function() {
        var $form = $("#form-amount-input, .balance-group");
        var $input = $form.find("input");
        $(document).on("keyup","#form-amount-input, .balance-group input", function(event) {
        var selection = window.getSelection().toString();
        if (selection !== "") {
          return;
        }
        if ($.inArray(event.keyCode, [38,40,37,39]) !== -1) {
          return;
        }
        var $this = $(this);
        var input = $this.val();
        input = input.replace(/[\D\s\._\-]+/g, "");
        input = input ? parseInt(input, 10) : 0;
        var formatted = input.toLocaleString("en-US");
        $this.val(formatted);
        $this.parent().parent().parent().find(".panel-data-value").text("Formula + " + formatted + ".00");
        if (formatted == "0") {
          $this.parent().parent().parent().find(".panel-data-value").text("Formula");
        }
      });
      });
    })(jQuery);
    $(".add-multi").click(function() {
      $(".multi-list").prepend(tempMulti);
    });
    $(".multi-list-each-delete").click(function() {
      $(this).parent().hide();
    });
    
    
    .form {
      margin-bottom: 40px;
      margin: 0 auto;
      width: 768px;
      font-family: 'Open Sans', sans-serif;
    }
    h1 {
     font-size: 13px;
      text-transform: uppercase;
      color: #0099ff;
      margin-bottom: 24px;
    }
    .input-text {
      height: 34px;
      border: solid 1px #c4c4c4;
      width: 366px;
      font-size: 13px;
      padding: 0 12px 0 12px;
      margin-bottom: 24px;
      color: #333;
      border-radius: 0;
      background-color: transparent;
    }
    .input-text:focus {
      border: solid 1px #00c983 !important; 
    }
    ::placeholder {
      color: #c4c4c4; 
      font-size: 13px;
      text-align: left !important;
    }
    .form-input-label {
      display: block;
      font-size: 12px;
      font-weight: 700;
      margin-bottom: 8px;
      color: #333;
    }
    .input-disabled {
      background-color: #eee; 
    }
    .form-unit {
      position: relative;
      vertical-align: top;
    }
    .input-select-btn {
      width: 34px;
      height: 34px;
      position: absolute;
      top: 25px;
      right: 0;
      text-align: center;
      line-height: 34px;
      cursor: pointer;
      z-index: -999;
    }
    .dropdown-btn-wrapper-clear {
      border-left: solid 1px #c4c4c4; 
    }
    .input-select-btn i {
      color: #666 !important; 
    }
    .on-disabled-btn {
      border: solid 1px #c4c4c4;
      background-color: #fff;
    }
    .input-select-btn i {
      font-size: 12px;
      color: #333;
    }
    .form-row {
      display: block;
      width: 100%;
      margin: 0 !important;
    }
    .form-divided {
      display: inline-block;
    }
    .form-divided-left {
      margin-right: 32px;
    }
    .btn-label {
      background-color: #eee; 
    }
    .spinner-group {
      position: absolute; 
      width: 16px;
      height: 26px;
      top: 4px;
      right: 44px;
    }
    .spinner-up,
    .spinner-down {
      height: 13px;
      line-height: 13px;
      display: block;
    }
    .spinner-down {
      top: 12px !important; 
    }
    .spinner-up i,
    .spinner-down i {
      line-height: 13px;
    }
    input[type=number]::-webkit-inner-spin-button, 
    input[type=number]::-webkit-outer-spin-button { 
      -webkit-appearance: none; 
      margin: 0; 
    }
    .input-with-spinner {
      text-align: right;
      padding-right: 32px; 
    }
    #amount-input {
      width: 100% !important; 
    }
    .amount-spinner-group {
      right: 10px; 
    }
    .add-multi {
      height: 40px;
      width: 100%;
      text-align: center;
      line-height: 40px;
      border: dashed 2px #eaeaea;
      font-size: 13px;
      cursor: pointer;
      margin-bottom: 8px;
    }
    .add-multi:hover {
      background-color: #f8f8f8; 
    }
    .add-multi i {
      font-size: 10px; 
      transform: translateY(-1px);
      margin-left: 4px;
    }
    .multi-list-each {
      background-color: #f8f8f8;
      display: block;
      width: 100%;
      padding: 16px 24px 12px;
      position: relative;
      margin-bottom: 8px;
    }
    .multi-list-each input {
      background-color: #fff; 
    }
    .multi-form-group {
      position: relative;
      width: 100%;
    }
    .multi-form-group input { 
      width: 100%;
      margin-bottom: 0;
    }
    .spinner-group-year {
      right: 2px; 
    }
    #balance-currency {
      position: absolute;
      z-index: 99;
      top: 0;
      left: 0;
      color: #333;
      text-decoration: none;
    }
    .multi-col {
      display: inline-block;
      vertical-align: top;
      padding-right: 16px;
      padding-left: 16px;
    }
    .multi-col:first-child {
      padding-left: 0;
    }
    .multi-col:last-child {
      padding-right: 0;
    }
    .multi-col input {
      margin-bottom: 0; 
    }
    .multi-list-each-delete {
      position: absolute; 
      right: 24px;
      top: 50%;
      transform: translateY(-50%);
    }
    .multi-list-each-delete i {
      font-size: 12px; 
    }
    @media (max-width: 767px) and (min-width: 576px) {
      .form {
        padding-left: 16px;
        padding-right: 16px;
        width: 100%;
      }
      
      .form-divided-left {
        margin-right: 24px;
      }
      
      .form-divided {
        width: calc(50% - 14px);
      }
      
      .input-text,
      textarea {
        display: inline-block;
        width: 100%;
      }
      
      .input-select-btn {
        right: 0;
      }
      
      .labeled-row {
        display: block;
        width: 100%;
      }
      
      .form-unit .select2-container, .form-unit .select2-selection {
          width: 100% !important;
      }
    }
    @media (max-width: 575px) {
      .form {
        padding-left: 16px;
        padding-right: 16px;
        width: 100%;
      }
      
      .form-divided {
        display: block; 
        width: 100%;
      }
      
      .form-divided-left {
        margin-right: 0; 
      }
      
      .input-text,
      textarea {
        display: inline-block;
        width: 100%;
      }
      
      .labeled-row {
        display: block;
        width: 100%;
      }
      .form-unit .select2-container, .form-unit .select2-selection {
          width: 100% !important;
      }
      
      .multi-col {
        margin-bottom: 16px; 
        padding-left: 0;
        padding-right: 0 !important;
      }
      
      .multi-list-each-delete {
        bottom: 8px;
        top: auto;
        left: 50%;
        transform: translateX(-50%);
        text-align: center;
        color: #999;
      }
      
      .multi-list-each-delete .button:hover {
        background-color: #eee;
        color: #999;
        text-decoration: none;
      }
    }
    
    
    <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.0.11/css/all.css" integrity="sha384-p2jx59pefphTFIpeqCcISO9MdVfIm4pNnsL08A6v5vaQc4owkQqxMV8kg4Yvhaw/" crossorigin="anonymous">
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
    <link href="https://fonts.googleapis.com/css?family=Open+Sans:400,400i,700,700i" rel="stylesheet">
    <div class="form">
      <div class="form-row">
        <div class="form-unit">
          <div class="multi-attribute">
            <label class="form-input-label">Multi-Attributes Input</label>
            <div class="add-multi">Add item <i class="fas fa-plus"></i></div>
            <ul class="multi-list">
              <li class="multi-list-each">
                <div class="col-33 multi-col">
                  <label class="form-input-label">Year</label>
                  <div class="multi-form-group">
                    <input class="year-input input-text input-with-spinner" type="number" min="0" placeholder="Add year">
                    <a />
                    <div class="spinner-group spinner-group-year">
                      <a class="spinner-up"><i class="fas fa-caret-up"></i></a>
                      <a class="spinner-down"><i class="fas fa-caret-down"></i></a>
                    </div>
                  </div>
                </div>
                <div class="col-33 multi-col">
                  <label class="form-input-label">Balance Increase</label>
                  <div class="balance-group multi-form-group">
                    <input class="balance-input input-text input-with-spinner" type="text" placeholder="Add balance">
                    <a />
                    <div class="spinner-group spinner-group-year">
                      <a class="spinner-up"><i class="fas fa-caret-up"></i></a>
                      <a class="spinner-down"><i class="fas fa-caret-down"></i></a>
                    </div>
                  </div>
                </div>
                <div class="col-33 multi-col">
                  <div class="panel-data panel-data-vertical">
                    <div class="panel-data-label">
                      Total Balance
                    </div>
                    <div class="panel-data-value">
                      Formula
                    </div>
                  </div>
                </div>
                <div class="multi-list-each-delete"><i class="fas fa-trash"></i></div>
              </li>
            </ul>
          </div>
        </div>
      </div>
    </div>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
    <script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
    <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.4.1/js/bootstrap-datepicker.min.js"></script>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.4.1/css/bootstrap-datepicker3.css"/>
    <link href="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.1/css/select2.min.css" rel="stylesheet" />
    <script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.1/js/select2.min.js"></script>
    
    

  • var tempMulti;
    $(document).ready(function() {
      resizeMultiPadding();
      tempMulti = $(".multi-list").html();
    });
    $(window).resize(function() {
      resizeMultiPadding();
    });
    function resizeMultiPadding() {
      if ($(window).width() >= 576) {
        var padding =  $(window).width() * 0.04;
        $(".multi-col").css({"padding-right": padding + "px"});
        $(".multi-col:last-child").css({"padding-right": "0"});
        $(".multi-list-each-delete").html("<i class='fas fa-trash'></i>");
      }
      else {
        $(".multi-list-each-delete").html("<a class='button footer-btn text-btn'><span><i class='fas fa-trash'></i>Delete</span></a>");
      }
    }
    $(document).on("click",".spinner-up",function() {
      var amount = parseInt($(this).parent().prev().prev().val()) || 0;
      amount += 1;
      $(this).parent().prev().prev().val(amount);
    });
    $(document).on("click",'.spinner-down',function() {
      var value = $(this).parent().prev().prev().val();
      var amount = parseInt(value) || 0;
      if (amount > 0) {
        amount -= 1; 
      }
      $(this).parent().prev().prev().val(amount);
    });
    (function($, undefined) {
      "use strict";
      $(function() {
        var $form = $("#form-amount-input, .balance-group");
        var $input = $form.find("input");
        $input.on("keyup", function(event) {
        var selection = window.getSelection().toString();
        if (selection !== "") {
          return;
        }
        if ($.inArray(event.keyCode, [38,40,37,39]) !== -1) {
          return;
        }
        var $this = $(this);
        var input = $this.val();
        input = input.replace(/[\D\s\._\-]+/g, "");
        input = input ? parseInt(input, 10) : 0;
        var formatted = input.toLocaleString("en-US");
        $this.val(formatted);
        $this.parent().parent().parent().find(".panel-data-value").text("Formula + " + formatted + ".00");
        if (formatted == "0") {
          $this.parent().parent().parent().find(".panel-data-value").text("Formula");
        }
      });
      });
    })(jQuery);
    $(".add-multi").click(function() {
      $(".multi-list").prepend(tempMulti);
    });
    $(".multi-list-each-delete").click(function() {
      $(this).parent().hide();
    });
    
    
    .form {
      margin-bottom: 40px;
      margin: 0 auto;
      width: 768px;
      font-family: 'Open Sans', sans-serif;
    }
    h1 {
     font-size: 13px;
      text-transform: uppercase;
      color: #0099ff;
      margin-bottom: 24px;
    }
    .input-text {
      height: 34px;
      border: solid 1px #c4c4c4;
      width: 366px;
      font-size: 13px;
      padding: 0 12px 0 12px;
      margin-bottom: 24px;
      color: #333;
      border-radius: 0;
      background-color: transparent;
    }
    .input-text:focus {
      border: solid 1px #00c983 !important; 
    }
    ::placeholder {
      color: #c4c4c4; 
      font-size: 13px;
      text-align: left !important;
    }
    .form-input-label {
      display: block;
      font-size: 12px;
      font-weight: 700;
      margin-bottom: 8px;
      color: #333;
    }
    .input-disabled {
      background-color: #eee; 
    }
    .form-unit {
      position: relative;
      vertical-align: top;
    }
    .input-select-btn {
      width: 34px;
      height: 34px;
      position: absolute;
      top: 25px;
      right: 0;
      text-align: center;
      line-height: 34px;
      cursor: pointer;
      z-index: -999;
    }
    .dropdown-btn-wrapper-clear {
      border-left: solid 1px #c4c4c4; 
    }
    .input-select-btn i {
      color: #666 !important; 
    }
    .on-disabled-btn {
      border: solid 1px #c4c4c4;
      background-color: #fff;
    }
    .input-select-btn i {
      font-size: 12px;
      color: #333;
    }
    .form-row {
      display: block;
      width: 100%;
      margin: 0 !important;
    }
    .form-divided {
      display: inline-block;
    }
    .form-divided-left {
      margin-right: 32px;
    }
    .btn-label {
      background-color: #eee; 
    }
    .spinner-group {
      position: absolute; 
      width: 16px;
      height: 26px;
      top: 4px;
      right: 44px;
    }
    .spinner-up,
    .spinner-down {
      height: 13px;
      line-height: 13px;
      display: block;
    }
    .spinner-down {
      top: 12px !important; 
    }
    .spinner-up i,
    .spinner-down i {
      line-height: 13px;
    }
    input[type=number]::-webkit-inner-spin-button, 
    input[type=number]::-webkit-outer-spin-button { 
      -webkit-appearance: none; 
      margin: 0; 
    }
    .input-with-spinner {
      text-align: right;
      padding-right: 32px; 
    }
    #amount-input {
      width: 100% !important; 
    }
    .amount-spinner-group {
      right: 10px; 
    }
    .add-multi {
      height: 40px;
      width: 100%;
      text-align: center;
      line-height: 40px;
      border: dashed 2px #eaeaea;
      font-size: 13px;
      cursor: pointer;
      margin-bottom: 8px;
    }
    .add-multi:hover {
      background-color: #f8f8f8; 
    }
    .add-multi i {
      font-size: 10px; 
      transform: translateY(-1px);
      margin-left: 4px;
    }
    .multi-list-each {
      background-color: #f8f8f8;
      display: block;
      width: 100%;
      padding: 16px 24px 12px;
      position: relative;
      margin-bottom: 8px;
    }
    .multi-list-each input {
      background-color: #fff; 
    }
    .multi-form-group {
      position: relative;
      width: 100%;
    }
    .multi-form-group input { 
      width: 100%;
      margin-bottom: 0;
    }
    .spinner-group-year {
      right: 2px; 
    }
    #balance-currency {
      position: absolute;
      z-index: 99;
      top: 0;
      left: 0;
      color: #333;
      text-decoration: none;
    }
    .multi-col {
      display: inline-block;
      vertical-align: top;
      padding-right: 16px;
      padding-left: 16px;
    }
    .multi-col:first-child {
      padding-left: 0;
    }
    .multi-col:last-child {
      padding-right: 0;
    }
    .multi-col input {
      margin-bottom: 0; 
    }
    .multi-list-each-delete {
      position: absolute; 
      right: 24px;
      top: 50%;
      transform: translateY(-50%);
    }
    .multi-list-each-delete i {
      font-size: 12px; 
    }
    @media (max-width: 767px) and (min-width: 576px) {
      .form {
        padding-left: 16px;
        padding-right: 16px;
        width: 100%;
      }
      
      .form-divided-left {
        margin-right: 24px;
      }
      
      .form-divided {
        width: calc(50% - 14px);
      }
      
      .input-text,
      textarea {
        display: inline-block;
        width: 100%;
      }
      
      .input-select-btn {
        right: 0;
      }
      
      .labeled-row {
        display: block;
        width: 100%;
      }
      
      .form-unit .select2-container, .form-unit .select2-selection {
          width: 100% !important;
      }
    }
    @media (max-width: 575px) {
      .form {
        padding-left: 16px;
        padding-right: 16px;
        width: 100%;
      }
      
      .form-divided {
        display: block; 
        width: 100%;
      }
      
      .form-divided-left {
        margin-right: 0; 
      }
      
      .input-text,
      textarea {
        display: inline-block;
        width: 100%;
      }
      
      .labeled-row {
        display: block;
        width: 100%;
      }
      .form-unit .select2-container, .form-unit .select2-selection {
          width: 100% !important;
      }
      
      .multi-col {
        margin-bottom: 16px; 
        padding-left: 0;
        padding-right: 0 !important;
      }
      
      .multi-list-each-delete {
        bottom: 8px;
        top: auto;
        left: 50%;
        transform: translateX(-50%);
        text-align: center;
        color: #999;
      }
      
      .multi-list-each-delete .button:hover {
        background-color: #eee;
        color: #999;
        text-decoration: none;
      }
    }
    
    
    <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.0.11/css/all.css" integrity="sha384-p2jx59pefphTFIpeqCcISO9MdVfIm4pNnsL08A6v5vaQc4owkQqxMV8kg4Yvhaw/" crossorigin="anonymous">
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
    <link href="https://fonts.googleapis.com/css?family=Open+Sans:400,400i,700,700i" rel="stylesheet">
    <div class="form">
      <div class="form-row">
        <div class="form-unit">
          <div class="multi-attribute">
            <label class="form-input-label">Multi-Attributes Input</label>
            <div class="add-multi">Add item <i class="fas fa-plus"></i></div>
            <ul class="multi-list">
              <li class="multi-list-each">
                <div class="col-33 multi-col">
                  <label class="form-input-label">Year</label>
                  <div class="multi-form-group">
                    <input class="year-input input-text input-with-spinner" type="number" min="0" placeholder="Add year">
                    <a />
                    <div class="spinner-group spinner-group-year">
                      <a class="spinner-up"><i class="fas fa-caret-up"></i></a>
                      <a class="spinner-down"><i class="fas fa-caret-down"></i></a>
                    </div>
                  </div>
                </div>
                <div class="col-33 multi-col">
                  <label class="form-input-label">Balance Increase</label>
                  <div class="balance-group multi-form-group">
                    <input class="balance-input input-text input-with-spinner" type="text" placeholder="Add balance">
                    <a />
                    <div class="spinner-group spinner-group-year">
                      <a class="spinner-up"><i class="fas fa-caret-up"></i></a>
                      <a class="spinner-down"><i class="fas fa-caret-down"></i></a>
                    </div>
                  </div>
                </div>
                <div class="col-33 multi-col">
                  <div class="panel-data panel-data-vertical">
                    <div class="panel-data-label">
                      Total Balance
                    </div>
                    <div class="panel-data-value">
                      Formula
                    </div>
                  </div>
                </div>
                <div class="multi-list-each-delete"><i class="fas fa-trash"></i></div>
              </li>
            </ul>
          </div>
        </div>
      </div>
    </div>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
    <script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
    <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.4.1/js/bootstrap-datepicker.min.js"></script>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.4.1/css/bootstrap-datepicker3.css"/>
    <link href="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.1/css/select2.min.css" rel="stylesheet" />
    <script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.1/js/select2.min.js"></script>
    
    

あなたの答え