[英]get jQuery variable in php from one page to another
I have a loop on my archive-tour page in which I output dates of on week after then the selected date. 我的归档浏览页面上有一个循环,在该循环中,我输出所选日期之后一周的日期。
<ul class="uol">
<?php
$start = strtotime($_GET['date']);
$dates = array();
for ($i = 0; $i <= 7; $i++) {
$date = date('Y-m-d', strtotime("+$i day", $start));
$date1 = $date;
$day = date('D', strtotime($date1));
$date = explode('-', $date);
$dateinput = date('Y-m-d', strtotime("+$i day", $start));
$date = $date[2];
echo '<li class="lia"><input type="hidden" class="getdate" value="'.$dateinput.'"><a href="#tabs-0" class="date">' . $date . ' ' . $day . '</a></li>';
}
?>
<li class="lia" style="background-color:blue"><a style="background- color:blue" href="#tabs-0" class="date tdate"></a></li>
</ul>
Here i have another loop on buttons as seen below. 在这里,我在按钮上有另一个循环,如下所示。 1:00 am - 2:00 am...... 凌晨1:00-凌晨2:00 ...
<button type="button" style="background-color:blue" id="ttime<?php echo $post->ID?>" class="btn btn-default time-pick tt_time" value=""></button>
for ($i = 0; $i <= 23; $i++) {
am = "";
if ($i <= 12) {
$am = "am";
} else {
$am = "pm";
}
echo '<button type="button" class="btn btn-default">' . $i.':00 ' . $am . ' - ' . ++$i .':00 '. $am . '</button> ';
--$i;
}
Now user can select date and according time to book tour. 现在,用户可以选择日期和时间预订游览。 i am getting the selected time and date and i want to highlight the above date and time accordingly. 我正在获取选定的时间和日期,我想相应地突出显示上述日期和时间。 currently setting time and date outer then the loop. 当前将时间和日期设置在循环之外。 but i want to match date with selected date, if it present then highlight it and same for the time. 但我想将日期与选定的日期匹配,如果存在,则将其突出显示,并且时间相同。 for example in user selects 9:00 am - 10:00 am then my code add one more button with this time. 例如,在用户选择上午9:00-上午10:00的同时,我的代码这次又添加了一个按钮。 i want to highlight the existing when by applying a if condition in loop that if date=selcted_date then highlight that one. 我想通过循环应用if条件来突出显示现有内容,如果条件为date = selcted_date,则突出显示该条件。
jQuery('#time<?php echo $post->ID?>').html(t_time);
$(".tdate").html(date);
how can i send the jquery variable t_time from footer page to archive page and get it on archive page in php so that i can use it in if condition. 我如何从页脚页将jquery变量t_time发送到存档页面,并在php的存档页面中获取它,以便在有条件的情况下可以使用它。 Remember its is wordpress. 记住它是wordpress。
In jquery you can use localStorage
. 在jquery中,您可以使用localStorage
。
localStorage.setItem('t_time','Your setTime' ); //set your value
And to get 并得到
localStorage.getItem('t_time'); //Get your value
Use jquery's $.post()
as follows.. 使用jquery的$.post()
如下。
var ttime = jQuery('#time<?php echo $post->ID?>').html();
$.post('php_file_name.php',{'ttime':ttime},function(data,status){
});
And in your php file.. 并在您的php文件中。
$time = $_POST['ttime'];//get ttime send from jquery
//echo $time
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.