jquery .load - 如何使用 javascript 和 jQuery 定位加载的文件 [英] jquery .load - how to target the loaded file with javascript and jQuery
问题描述
如果我有一个模板 index.html 并使用 jquery.load 包含一个带有 html 的文件,例如 $('#targetDiv').load('includes/inc1.html');
它.如何在 index.html 中使用 javascript 和 jQuery 定位 inc1.html 中的内容
If I have a template index.html and use jquery.load to include a file with html e.g $('#targetDiv').load( 'includes/inc1.html' );
into it. How do I target the content in inc1.html with both javascript and jQuery from within index.html
假设 inc1.html 包含 <div id="content">10</div>
并且我想使用 document.getElementById 将值从 10 更改为 20("content").innerHTML = "20";
在 index.html 的脚本标签内?谢谢
let's say inc1.html contains <div id="content">10</div>
and I want to change the value from 10 to 20 using document.getElementById("content").innerHTML = "20";
within the script tags in index.html?
Thanks
推荐答案
我在评论中关于设置回调函数的建议.
What I suggested in the comments about setting a callback function.
$('#targetDiv').load( 'includes/inc1.html', function(){
$('#content').html("20");
});
这篇关于jquery .load - 如何使用 javascript 和 jQuery 定位加载的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!