gpt4 book ai didi

javascript - jQuery等js使用div.load时未定义src

转载 作者:行者123 更新时间:2023-11-28 06:12:00 24 4
gpt4 key购买 nike

使用 jQuery load 加载页面时:

$("#myDiv").load("page.php",{foo: bar});

头包含在索引中:

<head>
<script src="/assets/plugins/jQuery/jQuery-2.1.4.min.js"></script>
<script src="/assets/plugins/jquery-print/jquery.print.js" ></script>
\\others js src
</head>

在此div上找不到内容是page.php:

<div id="myDiv">
\\if i call $("#otherDiv").print()
</div>

.print() 函数不存在,该函数已包含在索引头中

知道这个 div View 包含在 head 索引中吗?

最佳答案

\if i call $("#otherDiv").print()

调用.print()时,document中是否存在#otherDiv?即使在 document 中找不到任何元素,jQuery() 也会返回一个对象。您收到的错误消息可能是 .print() 不是 DOM 中不存在的元素的函数?

如果 .load() 成功将 #myDiv html 设置为 #otherDiv,请尝试使用 .load() 当元素存在于 document

中时调用 .print() 的回调函数
$("#myDiv").load("page.php", {foo: bar}, function() {
$("#otherDiv").print();
});

关于javascript - jQuery等js使用div.load时未定义src,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36299179/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com