Everyone knows that if a JS variable wants to obtain the PHP variable sent from the background, it can be written like this:
<?php $aaa = '111'; ?> var aaa = <?php echo $aaa; ?>;
Then how do we pay the value of the JS variable directly to the PHP variable? Woolen cloth?
The first method is also the most common method:
No refresh: use ajax to pass parameters;
With refresh: submit directly with the form Or directly follow the jump link;
The second value-passing method:
The example is date processing for js variables:
$c = "<script>document.write(leaderTask_info['end_time']);</script>"; echo formatTime($c);//leaderTask_info['end_time']是js变量 /** * 将截止时间秒数转换为日期制 */ function formatTime($date){ $t = $date - time(); $f = array( '31536000'=>'年', '2592000'=>'个月', '604800'=>'星期', '86400'=>'天', '3600'=>'小时', '60'=>'分钟', '1'=>'秒' ); foreach($f as $k=>$v){ $c = floor($t/(int)$k); if($c > 0){ if(0 != $c){ return "剩余".$c.$v; } } } return "已截止"; }
In this way, the value of the js variable can be assigned to the php variable without using ajax and jump.
Recommended tutorial: js video tutorial
The above is the detailed content of js does not jump to pass value php. For more information, please follow other related articles on the PHP Chinese website!