使用jQuery选择包含php的html元素

使用jQuery选择包含php的html元素,php,html,jquery,dom,Php,Html,Jquery,Dom,我想用jQuery选择一个包含的html元素。我怎样才能做到这一点 index.php <?php <html> <head> ... </head> <body> include('file.php'); </body> <html> ?> 尝试在页面完全加载后执行脚本 $(wind

我想用jQuery选择一个包含的html元素。我怎样才能做到这一点

index.php

<?php
    <html>
        <head>
            ...
        </head>
        <body>
            include('file.php');
        </body>
    <html>
?>

尝试在页面完全加载后执行脚本

$(window).on("load", function() {
   let test = $('.test');
   console.log(test);
}); 

尝试在页面完全加载后执行脚本

$(window).on("load", function() {
   let test = $('.test');
   console.log(test);
}); 

代码应按如下方式组织:。这可以被HTML包围,例如,
。这将显示:你好

那么…你看到问题了吧,关于

<?php
    <html>
        <head>
            ...
        </head>
        <body>
            include('file.php');
        </body>
    <html>
?>

HTML在PHP中是。你想要这个:

<html>
    <head>
        ...
    </head>
    <body>
        <?php include('file.php'); ?>
    </body>
<html>

...

当然,这段代码根本不应该执行,因为
代码应该按如下方式组织:
。这可以被HTML包围,例如,
。这将显示:你好

那么…你看到问题了吧,关于

<?php
    <html>
        <head>
            ...
        </head>
        <body>
            include('file.php');
        </body>
    <html>
?>

HTML在PHP中是。你想要这个:

<html>
    <head>
        ...
    </head>
    <body>
        <?php include('file.php'); ?>
    </body>
<html>

...

当然,这段代码根本不应该执行,因为
确保js代码在html元素出现在DOM中或
文档中后运行。准备好了吗
事件。在DOM结构测试中是否显示?@sergeykuznetsov是的,它在DOM结构中。@u\u mulder我已经尝试使用document.ready,但不起作用:/
。代码甚至不应该像现在这样执行。确保js代码在html元素出现在DOM中或
文档中后运行。准备好了吗
事件。在DOM结构测试中显示了吗?@sergeykuznetsov是的,它在DOM结构中。@u\u mulder我已经尝试过使用document.ready,但它没有工作:/
。代码甚至不应该像现在这样执行。