我输入了id
和ballance
,id
作为复选框,ballance
作为文本输入。我想在选中id
时,ballance
请求与选中的id
相匹配。但目前所有ballance
均已提出请求。如何从前端和后端解决问题?
我的观点:
我的查看代码:
<th>
<div>
<input name="id[]" value="{{$item->id}}" type="checkbox"> <label class="" for="{{$item->id}}"></label>
</div>
</th>
<td> {{ $item->id }} </td>
<td>
<input type="text" class="form-control form-control-sm txtInt saldoChild" name="ballance[]" size="1" id="{{$item->id}}" value="0">
</td>
我的要求退回:
我的后端:
public function store(Request $request)
{
return $request;
}
谢谢..
答案 0 :(得分:1)
最简单的方法是拥有余额阵列。因此,您可以获得那些不为0的值并将其推入新数组,然后就可以使用了! id数组的第一个索引用于新数组的第一个索引。您可以将它们存储在另一个数组或数据库中
答案 1 :(得分:1)
当html中的input
为disabled
时,该值将不会发送给控制器。
所以试试这个:
<script>
$('input[type="checkbox"]').on("change", function(){
if($(this).is(":checked")){
$(this).closest('tr').find('.saldoChild').prop("disabled",false); //Enable the textBox
}
else{
$(this).closest('tr').find('.saldoChild').prop("disabled",true); //Disable the textbox
}
});
</script>
并且在页面加载时,您必须Disable
全部input type text
,而checkbox
中的tr
未被选中。