Home > Web Front-end > JS Tutorial > body text

js does not jump to pass value php

王林
Release: 2019-10-17 17:57:00
Original
3280 people have browsed it

js does not jump to pass value php

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 = &#39;111&#39;;
?>
var aaa = <?php 
echo $aaa;
?>;
Copy after login

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[&#39;end_time&#39;]);</script>";
echo formatTime($c);//leaderTask_info[&#39;end_time&#39;]是js变量
/**
* 将截止时间秒数转换为日期制
*/
function formatTime($date){
  $t = $date - time();
  $f = array(
    &#39;31536000&#39;=>&#39;年&#39;,
    &#39;2592000&#39;=>&#39;个月&#39;,
    &#39;604800&#39;=>&#39;星期&#39;,
    &#39;86400&#39;=>&#39;天&#39;,
    &#39;3600&#39;=>&#39;小时&#39;,
    &#39;60&#39;=>&#39;分钟&#39;,
    &#39;1&#39;=>&#39;秒&#39;
  );
  foreach($f as $k=>$v){
    $c = floor($t/(int)$k);
    if($c > 0){
      if(0 != $c){
        return "剩余".$c.$v;
      }
    }
  }
  return "已截止";
}
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template