我有一个复选框,想将复选框的值提交给数据库。我宁愿没有提交按钮,
<label>OFF<input type="checkbox" checked><span class="lever"></span>ON</label>
最佳答案
你可以这样试试
$(document).ready(function(){
$('#aksi').change(function() {
var returnVal = confirm("Are you sure?");
if(returnVal){
postToServer($(this).prop("checked"))
}else{
$(this).prop("checked", !$(this).is(":checked"));
}
});
});
function postToServer(state){
let value = (state) ? 1 : 0;
alert('Posted Value: ' + value);
$.ajax({
type: "POST",
url: "http://your-server.com/update/aski",
data: {"aski":value},
success: function(response){
//handle response
}
});
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<label>OFF<input type="checkbox" id="aksi" checked><span class="lever"></span>ON</label>
关于html - 如何在没有laravel提交按钮的情况下插入值复选框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50979494/