Laravel复选框在实时搜索中总是返回true
问题描述:
我有一个复选框有问题:在进行LIVEsearch时,复选框的值始终设置为1/true。当我在正常搜索(没有js文件)中做同样的事情时,我没有这个问题。Laravel复选框在实时搜索中总是返回true
{{ Form::checkbox('deleted', '1' , null , array('id' => 'search-deleted'))}}
比我的JavaScript代码(我想这个问题是让复选框的值),正如你看到的,我有一些
<script>
$(document).ready(function(){
$(".search").keyup(function(){
var staffid= $("#search-staffid").val();
var firstName= $("#search-first-name").val();
var lastName= $("#search-last-name").val();
var birthday= $("#search-birthday").val();
var children= $("#search-children").val();
var deleted= $("#search-deleted").val();
if(staffid == "" && firstName == "" && lastName == "" && birthday == "" && children == "") {
$("#liveResult").html("<b>Suchergebnisse werden hier angezeigt</b>");
}else {
$.get("{{ url('demos/livesearch') }}" +
'?staffid=' + staffid +
'&first_name=' + firstName +
'&last_name=' + lastName +
'&birthday=' + birthday +
'&children=' + children +
'&deleted=' + deleted
, function(data) {
$("#liveResult").html(data);
});
}
});
});
</script>
:我的复选框的所有代码 第一其他领域,他们工作没有任何问题。我的控制器的最后代码:
public function liveSearch(Request $request)
{
$data = [
'id' => $request->staffid,
'first_name' => $request->first_name,
'last_name' => $request->last_name,
// converts date format only if birthday != null
'birthday' => ($request->birthday ? date('Y-m-d', strtotime($request->birthday)) : null),
'children' => $request->children,
'deleted' => $request->deleted
];
if (is_null($data['id']) && is_null($data['first_name']) && is_null($data['last_name']) && is_null($data['birthday']) && is_null($data['children']))
{
return view('staff.livesearch');
}
else
{
dd ($data['deleted']);
}
}
答
您的复选框的value
总是1
;你真正想知道的是它是否被检查。
// boolean
var deleted = $("#search-deleted").prop('checked');
是的,非常感谢! –