我有一个包含一周日期的HTML表格
|Monday|Tuesday|Wednesday|Thursday|Friday|Saturday|Sunday|
|data |data |---- |---- |---- |---- |--- |
并且有一个Relation,Route-Client,并且我想要显示(或不显示)列表,从表格路径的复选框中查看值1。我将复选框数据保存为0和1,工作日1,自由第0天,并且我使用此方法提取0和1:
在Form :: open()
中<td>Route:</td>
<select id="day" name="day" onchange="showDays()">
@foreach($route as $ro)
<option value="{{ $ro['id'] .','. $ro['monday'] .','. $ro['tuesday'] .','. $ro['wednesday'] .','. $ro['thursday'] .','. $ro['friday'] .','. $ro['saturday'] .','. $ro['sunday'] }}">
{{ $ro['name'] }}
</option>
@endforeach
</select>
<input id="id_route" type=hidden name="id_route">
Javascript方法
function showDays() {
var day = $("#day").val();
alert(day);
var days= day.slice(-13);
alert(days);
//I pass the respective binary number to the respective day
var monday= document.getElementById("monday");
monday= day.slice(-13,-12);
$("#monday").val(monday); //don't know if this can help me in other javascript function
alert(monday);
var tuesday= document.getElementById("tuesday");
tuesday= day.slice(-11,-10);
$("#tuesday").val(tuesday);
alert(tuesday);
var wednesday= document.getElementById("wednesday");
wednesday= day.slice(-9,-8);
$("#wednesday").val(wednesday);
alert(wednesday);
var thursday= document.getElementById("thursday");
thursday= day.slice(-7,-6);
$("#thursday").val(thursday);
alert(thursday);
var friday= document.getElementById("friday");
friday= day.slice(-5,-4);
$("#friday").val(friday);
alert(friday);
var saturday= document.getElementById("saturday");
saturday= day.slice(-3,-2);
$("#saturday").val(saturday);
alert(saturday);
var sunday= document.getElementById("sunday");
sunday= day.slice(-1);
$("#sunday").val(sunday);
alert(sunday);
}
在我的HTML表格中:
<tr><!--I been thinking on doing something like this -->
<th <a id="monday" onchange="showDays()" value="{{$route['monday']}}">MONDAY</th>
<th <a id="tuesday" onchange="showDays()" value="{{$route['tuesday']}}">TUESDAY</th>
<th <a id="wednesday" onchange="showDays()" value="{{$route['wednesday']}}">WEDNESDAY</th>
<th <a id="thursday" onchange="showDays()"value="{{$route['thursday']}}">THURSDAY</th>
<th <a id="friday" onchange="showDays()" value="{{$route['friday']}}">FRIDAY</th>
<th <a id="saturday" onchange="showDays()" value="{{$route['saturday']}}">SATURDAY</th>
<th <a id="sunday" onchange="showDays()" value="{{$route['sunday']}}">SUNDAY</th>
</tr>
@foreach($client as $ct)
<tr> <!--In this moment I just fill all the days with all the clients, but the idea is to fill the days respect the clients assigned by that day-->
<td id="mondayTD">{{ $ct->client_name }}</td>
<td id="tuesdayTD">{{ $ct->client_name }}</td>
<td id="wednesdayTD">{{ $ct->client_name }}</td>
<td id="thursdayTD">{{ $ct->client_name }}</td>
<td id="fridayTD">{{ $ct->client_name }}</td>
<td id="saturdayTD">{{ $ct->client_name }}</td>
<td id="sundayTD">{{ $ct->client_name }}</td>
</tr>
@endforeach
如果我这样做的话,我会在表格的标题上找到数字1,1,1,1,1,1,1,它们是在我的数据库上创建的最后一条路线的二进制值(目前不在#39;知道如何更改这些值,只显示最后创建的值。
我需要尊重我收到的值1或0,以决定是否显示该栏目,但我不知道该怎么做,如果有人可以帮助我,我将非常感激!谢谢!
答案 0 :(得分:0)
您可以创建一个php页面来打印表格。这将根据POST传递的复选框的值打印表。您只需使用ajax调用此页面并将响应放在所需的div中。
使用jQuery和.post(),这变得非常简单:
$.post( "tablepage.php", { monday: "1", tuesday: "0" })
.done(function( data ) {
$( "#div" ).html(data);
});
这应该是每次更改复选框时触发的函数的一部分。 tablepage.php将按帖子收到日期值,例如$_POST['monday']
。使用它们来生成表格。 $( "#divname" ).html(data);
代码将php脚本的输出传递给div。