-1

管理者が特定の割引タイプに対して割引を有効または無効に設定できるシステムがあります。割引値はデータベースに既に設定されています。

<li>Discount For Items</li>
<li><input type="checkbox" class="discount" value="1"></li>

<li>Discount For General Ordesr</li>
<li><input type="checkbox" class="discount" value="2"></li>

<li>Discount For Preferred Customer</li>
<li><input type="checkbox" class="discount" value="2"></li>

enablejQuery/Ajax を使用して行 (ブール値)をchecked更新discount typeしたい 。 本当にあなたの助けが必要です。私の説明が理解できることを願っています。uncheckeddiscount type

4

2 に答える 2

1

jQuery を使用すると、このようなことができますが、実際のデータベース操作を行うにはサーバー側のロジック (サービス) が必要です ( AJAX POST 要求と共に割引タイプをタイプとして渡します)。

    <li>Discount For Items</li>
    <li><input type="checkbox" class="discount" data-discount-type="all" /></li>

    <li>Discount For General Ordesr</li>
    <li><input type="checkbox" class="discount" data-discount-type="general" /></li>

    <li>Discount For Preferred Customer</li>
    <li><input type="checkbox" class="discount" data-discount-type="customer" /></li>

    // JavaScript
    $(function(){
       var url = 'my-php-file.php';

       $('input:checkbox').on('click', function(){
           var $this = $(this);
       if($this.prop('checked'))
          $.post(url,{type : $this.data('discount-type') }).done(function(response){
             // success custom logic
          });
      });
    });
于 2013-04-04T08:01:30.463 に答える
1

次のようなことを試すことができます:

$(document).ready(function(){
  $('input.discount').change(function(){

    $this = $(this);

    $.post(
      "my-php-file.php",
      {
        value: $this.val(),
        checked: $this.is(':checked')
      },
      function(data){
        // do something with returned data
      },
      'json'
    );
  });
});
于 2013-04-04T07:54:51.100 に答える