Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/276.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/453.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
当我从PHP回显jQuery时,它不工作_Php_Javascript_Jquery - Fatal编程技术网

当我从PHP回显jQuery时,它不工作

当我从PHP回显jQuery时,它不工作,php,javascript,jquery,Php,Javascript,Jquery,我只需要在php脚本的某些部分运行一些js,出于测试目的,我注释掉了php,所以我不打算在这里显示它 <!DOCTYPE HTML> <html> <head> <script src="jquery-1.9.1.min.js" type="text/javascript"></script> </head> <body> <?php echo '<script>

我只需要在php脚本的某些部分运行一些js,出于测试目的,我注释掉了php,所以我不打算在这里显示它

<!DOCTYPE HTML>
<html>
<head>
    <script src="jquery-1.9.1.min.js" type="text/javascript"></script>
</head>
<body>
    <?php
        echo '<script>
        var width = $(window).width();<---Not working down too 1A
        var height = $(window).height();
        var widthSTR = width.toString();
        widthSTR = widthSTR.concat("px");
        var heightSTR = height.toString();
        heightSTR = heightSTR.concat("px");
        heightSTR = " ".concat(heightSTR);
        var size = widthSTR.concat(heightSTR);
        $("body").css({
            "background-size" : size, <---1A and above ^
            "background" : "url(p.jpg) 50% 0 no-repeat fixed"<---1B
        });
        </script>
        ';
    ?>
</body>
</html>

您是否尝试过:

if($condition){
?>
 <script>
        var width = $(window).width();
        var height = $(window).height();
        var widthSTR = width.toString();
        widthSTR = widthSTR.concat("px");
        var heightSTR = height.toString();
        heightSTR = heightSTR.concat("px");
        heightSTR = " ".concat(heightSTR);
        var size = widthSTR.concat(heightSTR);
        $("body").css({
            "background-size" : size,
            "background" : "url(p.jpg) 50% 0 no-repeat fixed"
        });
        </script>

    ?>
<?php
}
if($condition){
?>
变量宽度=$(窗口).width();
var height=$(window.height();
var widthSTR=width.toString();
宽度str=宽度str.concat(“px”);
var heightSTR=height.toString();
heightSTR=heightSTR.concat(“px”);
heightSTR=“”.concat(heightSTR);
变量大小=宽度长度(高度长度);
$(“正文”).css({
“背景尺寸”:尺寸,
“背景”:“url(p.jpg)50%0无重复修复”
});
?>
您是否尝试过:

if($condition){
?>
 <script>
        var width = $(window).width();
        var height = $(window).height();
        var widthSTR = width.toString();
        widthSTR = widthSTR.concat("px");
        var heightSTR = height.toString();
        heightSTR = heightSTR.concat("px");
        heightSTR = " ".concat(heightSTR);
        var size = widthSTR.concat(heightSTR);
        $("body").css({
            "background-size" : size,
            "background" : "url(p.jpg) 50% 0 no-repeat fixed"
        });
        </script>

    ?>
<?php
}
if($condition){
?>
变量宽度=$(窗口).width();
var height=$(window.height();
var widthSTR=width.toString();
宽度str=宽度str.concat(“px”);
var heightSTR=height.toString();
heightSTR=heightSTR.concat(“px”);
heightSTR=“”.concat(heightSTR);
变量大小=宽度长度(高度长度);
$(“正文”).css({
“背景尺寸”:尺寸,
“背景”:“url(p.jpg)50%0无重复修复”
});
?>
将您的代码包装到:

jQuery(function($) {
  // Put your whole code here
});
如果您正在接触DOM,您应该将jQuery内容包装在该块中;这称为:用于文档加载。

将代码包装在块中:

jQuery(function($) {
  // Put your whole code here
});

如果您正在接触DOM,您应该将jQuery内容包装在该块中;这称为:用于文档加载。

如果完全加载DOM,则应在加载完后执行代码,这取决于加载的对象、宽度等

<!DOCTYPE HTML>
<html>
<head>
    <script src="jquery-1.9.1.min.js" type="text/javascript"></script>
</head>
<body>
    <?php
        echo '<script>
        $(document).ready(function(){
            var width = $(window).width();<---Not working down too 1A
            var height = $(window).height();
            var widthSTR = width.toString();
            widthSTR = widthSTR.concat("px");
            var heightSTR = height.toString();
            heightSTR = heightSTR.concat("px");
            heightSTR = " ".concat(heightSTR);
            var size = widthSTR.concat(heightSTR);
            $("body").css({
                "background-size" : size, <---1A and above ^
                "background" : "url(p.jpg) 50% 0 no-repeat fixed"<---1B
            });
        });
        </script>
        ';
    ?>
</body>
</html>


您的代码应该在加载完整的dom后执行,如果它取决于加载的对象,那么宽度等就可以了

<!DOCTYPE HTML>
<html>
<head>
    <script src="jquery-1.9.1.min.js" type="text/javascript"></script>
</head>
<body>
    <?php
        echo '<script>
        $(document).ready(function(){
            var width = $(window).width();<---Not working down too 1A
            var height = $(window).height();
            var widthSTR = width.toString();
            widthSTR = widthSTR.concat("px");
            var heightSTR = height.toString();
            heightSTR = heightSTR.concat("px");
            heightSTR = " ".concat(heightSTR);
            var size = widthSTR.concat(heightSTR);
            $("body").css({
                "background-size" : size, <---1A and above ^
                "background" : "url(p.jpg) 50% 0 no-repeat fixed"<---1B
            });
        });
        </script>
        ';
    ?>
</body>
</html>

我在要操作的元素中添加了“contenteditable”。示例:

然后jquery函数操纵html,我的php脚本在文档中回荡。我不知道为什么这里需要这样做,因为jquery操纵了其他没有关键字的元素,而普通javascript也成功地操纵了没有关键字的html元素。

我添加了“contenteditable”在我希望操纵的元素中。示例:


然后,jquery函数操纵html,我的php脚本在文档中回荡。我不知道为什么这里需要这样做,因为jquery操纵了其他没有该关键字的元素,而普通javascript也成功地操纵了没有该关键字的html元素。

你为什么要这样做?为什么要这样做顺序代码是什么样子的?我不知道你想完成什么。为什么你要使用PHP来回送脚本块;我看不出任何真正的原因,因为你没有使用变量或任何东西。你忘记了
$(function(){})
-document准备好了为什么要这样做?呈现的代码是什么样子的?我不知道你想完成什么。为什么你要用PHP来回显脚本块;我看不出任何真正的原因,因为你没有使用变量或任何东西?你忘了
$(function(){})
-document readyI不确定是否有些东西在PHP echo中不起作用,因此PHP标记:)我不确定是否有些东西在PHP echo中不起作用,因此PHP标记:)