php - 如何使用php代码访问javascript变量

标签 php javascript

        function al(){
        var selr = jQuery('#grid').jqGrid('getGridParam','selrow');
        if(selr){
            <?
                include_once("../../DB/singleton.php");
                $pDatabase = Database::getInstance();
                $c = $pDatabase->query("select c.city_title as 'City' from teamshuffle.tbl_city c, teamshuffle.tbl_sport_city s where c.tblcity_id = s.tblcity_id and s.tblsport_id = " . );
                while($r = mysql_fetch_array($c)){
                    echo("alert(\"" . $r[0] . selr . "\");");
                }
            ?>

        }
    }

这是我的 javascript 函数。我需要访问行中的变量“selr”

echo("alert(\"" . $r[0] . $d . "\");");

最佳答案

简短的回答:你不能。 PHP 是服务器端,JavaScript 是客户端。

长答案:

您可能无法“访问”该变量,但您可以在 ajax 请求中将值发送到任何需要它的 PHP 页面并在那里使用它。作为 POST 参数或查询参数。

关于php - 如何使用php代码访问javascript变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8590925/

相关文章:

php - 从 Php 插入日期

javascript - 何时执行动态加载到 head 中的 CSS

javascript - 如何使用jquery打印隐藏的div内容?

javascript - 将 HTML 附加到没有 innerHTML 的容器元素

javascript - 表格: password with images?

php - Wordpress 循环在页面循环开始时创建空白空间

php - 为什么会出现这种情况? mysqli_query() : Empty query in/home/evansbwg/public_html/Old Things/Website/insert. php 第 52 行

php - 如何使用dom php解析器

Javascript 地址栏黑客/技巧

javascript - 具有固定不均匀行的 HTML 表格