Home  >  Article  >  Web Front-end  >  js does not jump to pass value php

js does not jump to pass value php

王林
王林Original
2019-10-17 13:51:063256browse

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;
?>;

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 "已截止";
}

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!

Statement:
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
Previous article:Introduction to using NPMNext article:Introduction to using NPM