0

私はいくつかを持っています

<input type="text" name="price[]" value="100">
<input type="text" name="price[]" value="50">
<input type="text" name="price[]" value="10">
<input type="text" name="price[]" value="90">

入力フィールドもあります

<input type="text" name="Add" value="">

私が欲しい

  1. 各 price[] 入力フィールドの横に、その特定の price[] 入力フィールドから値を取得する独自の追加ボタンを配置します。
  2. 追加入力フィールドの値をそれに追加します
  3. 最後にその特定の価格[]入力フィールドの値を更新します

どうやってやるの?

4

1 に答える 1

0

価格[]-ボックスを繰り返してボタンをボタンに追加し、価格[]からボタンに値を設定するには、次のようにします

<input type="text" name="price[]" value="100">
<input type="text" name="price[]" value="50">
<input type="text" name="price[]" value="10">
<input type="text" name="price[]" value="90">

<script type="text/javascript">
$(document).ready(function() {
    $('input[name="price[]"]').each(function(i) {
        $(this).after('<button class="additionButton" price="'+$(this).val()+'">'+$(this).val()+'</button>');
    });
    //click
    $(".additionButton").on('click',function() {
        //original price, set on load
        alert($(this).attr('price'));
        //price in the input-field before the button (could be changed, think this is the idea)
        alert($(this).prev('input').val());
    });
});
</script>

残りの部分については、私はあなたが何を意味するのかわかりません、「追加」は価値がなく、あなたは真剣にある種の計算が必要ですか?しかし、自分で試してみてください。少なくとも繰り返しがありました。

于 2012-10-17T19:35:41.950 に答える