将php变量传递给jquery脚本不起作用 [英] Pass php variable to jquery script is not working

查看:70
本文介绍了将php变量传递给jquery脚本不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下jquery脚本:

I have the following jquery script:

<script>
        $(document).ready(function () {
            $(".clickable").click(function () {
                $(this).animate({left: '1030px'}, function () {
                    $(this).fadeOut("slow", function () {
                        document.location.href = $(this).get(0).id + ".php";
                    });
                });
            });

        });
        $(document).ready(function () {
            $("#Chi").animate({left: '0'}, {duration: 200, queue: false});
            $("#Dove").animate({left: '0'}, {duration: 400, queue: false});
            $("#Quando").animate({left: '0'}, {duration: 600, queue: false});
            $("#Cosa").animate({left: '0'}, {duration: 800, queue: false});
            var phpvariable=<? echo $row; ?>
            $('.dreams-photo-profile-mydream').css({"background": "url(\"/images/user.png\")"});
            $('.dreams-photo-profile-mydream').css({"background-repeat": "no-repeat"});
            $('.dreams-photo-profile-mydream').css({"background-position": "center"});
            $('.dreams-photo-profile-mydream').css({"background-size": "contain"});

        });

    </script>

我正试图像这样传递一个php变量:

And i'm trying to pass a php variable like so:

   <?php
    $gdb->connettiDB();
    $row = $gdb->getFotoProfilo(getId());
    ?>

 var phpvariable=<? echo $row; ?>

那是行不通的.当我在脚本中声明一个var时,所有内容似乎都被阻止了,我的动画无法正常工作,我也不知道为什么.谁能解释我该怎么做?

That 's not working. When i declare a var inside the script, everything seems blocked and my animations aren't working and I don't know why. Can anyone explain me how can I exactly do that?

推荐答案

错误使用php:-

var phpvariable=<? echo $row; ?>

应该是

 var your_variable='<?php echo $row; ?>';

这篇关于将php变量传递给jquery脚本不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆