我尝试使用post jquery插入表单数据,以便将数据成功处理到数据库中,但问题是如何在不重新加载表单的情况下重新恢复表单,因此在我更改后隐藏不再出现选项$(".access")
?
<button type="button" id="add-user" class="btn btn-success"><i class="fa fa-plus"></i> Add user</button>
</br>
<div class="row">
<div class="from-user" style="display: none">
<form id="form-add" class="form-horizontal">
<div class="form-group">
<div class="col-md-6">
<div class="nama">
<label for="nama">Name * :</label>
<input type="text" name="name" id="name" class="form-control" type="text" required />
<div class="help-block with-errors"></div>
</div>
</div>
</div>
<div class="form-group">
<div class="col-md-6">
<div class="nama">
<label for="nama">Address * :</label>
<input type="text" name="address" id="address" class="form-control" type="text" required />
<div class="help-block with-errors"></div>
</div>
</div>
</div>
<div class="form-group">
<div class="col-md-6">
<div class="view-access">
<label for="access">Access * :</label>
<select name="access" id="access" class="access form-control" required>
<option value="">Select</option>
<option value="0">Admin</option>
<option value="1">Staff</option>
<option value="2">Employees</option>
<option value="3">User</option>
</select>
<div class="help-block with-errors"></div>
</div>
</div>
</div>
<div class="form-group">
<div class="col-md-6">
<div class="view-section">
<label for="section">Section * :</label>
<select name="section" id="section" class="form-control" required>
<option value="">Select</option>
<option value="0">Hotel</option>
<option value="1">Cafe</option>
<option value="2">Restaurant</option>
</select>
<div class="help-block with-errors"></div>
</div>
</div>
</div>
<div class="form-group">
<div class="col-md-6">
<div class="view-status">
<label for="status">Status * :</label>
<select name="status" id="status" class="form-control" required>
<option value="">Select</option>
<option value="0">Active</option>
<option value="1">Deactive</option>
</select>
<div class="help-block with-errors"></div>
</div>
</div>
</div>
<div class="form-group">
<div class="col-md-6">
<div class="sub">
<button type="button" id="submit" class="btn btn-primary"><i class="fa fa-save"></i> Submit</button>
</div>
</div>
</div>
</form>
</div>
</div>
<script>
$(document).ready(function() {
$("#add-user").click(function() {
$(".from-user").toggle("slow");
});
$(".access").change(function(){
var value=$(this).val();
if(value == 2 || value == 3){
$('.view-section').hide();
$('.view-status').hide();
}else if(value == 1){
$('.view-section').show();
$('.view-status').hide();
}else{
$('.view-section').show();
$('.view-status').show();
}
});
$(document).on('click', '#submit', function(ev){
ev.preventDefault();
var btn_button = $(this);
$.post(base_url+"add.php", data, function(data){
$(".from-user").toggle("slow", function(){
$("#form-add")[0].reset();
$(".from-user").load(location.href + ".from-user");
});
});
});
})
</script>