首页 > 解决方案 > 将动态 javascript 变量传递给 PHP

问题描述

我想将一个 JavaScript 变量传递给 PHP,这是我的代码:

$('.info-button').on('click', function() {
         var flag = $(this).data('flag');

            if (flag) {
                var index3 = $(this).parent().parent().parent().find('img').attr('src');
                console.log(index3);
              $('.inner').css("display", "block");
            } else {
                    $('.inner').css("display", "none");
            }

            $(this).data('flag', !flag);
});

如何获取 index3,它是 PHP 的动态变量?

我试过:

<?php
   echo "<script>document.writeln(index3);</script>";
?>

但我得到index3 没有定义

标签: javascriptphpvariables

解决方案


推荐阅读