2017-06-04 70 views
0

大家好我用一个复选框,加载的形式,如果选中我想负荷形式否则去除形成波纹管是我的代码jQuery的:选中的复选框追加形式

$('.checkbox-primary').change(function() { 
     $url = $('.form-edit').attr('action'); 
     $form = $('.form-edit').serialize(); 
     $.post($url, $form ,function ($data) { 

      var x=document.getElementById("filebox_edit_hardcopylocation_warehouse"); 
      var warehouse=document.getElementById("filebox_edit_hardcopylocation_warehouse"); 
      if(x){ 
       $('.panel-footer').removeChild(warehouse); 
       alert("yes"); 
      } 
      else 
      { 
       $('.form-edit').append('<div class="form-group"> <label class="col-md-3 col-xs-12 control-label">WareHouse: </label> <div class="col-md-6 col-xs-12"> <select id="filebox_edit_hardcopylocation_warehouse" name="filebox_edit[hardcopylocation][warehouse]" class="form-control"><option value="">Please Select Warehouse</option><option value="6">HQ4</option><option value="7">KTC</option></select> </div> </div> <select id="filebox_edit_hardcopylocation_floor" name="filebox_edit[hardcopylocation][floor]" class="form-control"><option value="">Please Select Floor</option><option value="1">first floor</option><option value="2">second floor</option><option value="3">second floor</option><option value="4">first floor</option></select><select id="filebox_edit_hardcopylocation_room" name="filebox_edit[hardcopylocation][room]" class="form-control"><option value="">Please Select Room</option><option value="9">R122</option><option value="10">R2</option></select><select id="filebox_edit_hardcopylocation_rack" name="filebox_edit[hardcopylocation][rack]" class="form-control"><option value="">Please Select Rack</option><option value="15">RA3456</option><option value="16">RA1</option><option value="17">RA2</option><option value="18">RA39</option></select>') 

      } 

     }) 
    }); 
+0

在-1雨之前,什么似乎是问题:)任何错误等也不混合香草js API和jQuery是丑陋的af并且容易出错 –

+0

@VitaliyTerziev我想在删除复选框时删除表格 –

+0

添加一些HTML会很有用。现在我们必须猜测每个ID /类的用途。 – Gerard

回答

0

使用jQuery,您可以检查:

$('.checkbox-primary').change(function() { 
    $(this).is(":checked") { 
      // checkbox is checked 
    } else { 
      // It is unchecked 
    } 
}