Javascript 如何填充从另一个html页面加载的div

Javascript 如何填充从另一个html页面加载的div,javascript,jquery,html,autofill,Javascript,Jquery,Html,Autofill,我试图从另一个html页面加载一个div,然后用主html页面中的值填充它。 我的div已正确加载和显示,但它似乎不想填充。以下是我目前掌握的情况: $("#valider").click(function() { $("#ag_pub_panneau_detail_html").load( "https://tc610/ag_pub_collecte/Ag_pub_panneau_detail.html #ag_pub_panneau_detail_master_div");

我试图从另一个html页面加载一个div,然后用主html页面中的值填充它。 我的div已正确加载和显示,但它似乎不想填充。以下是我目前掌握的情况:

$("#valider").click(function() {
    $("#ag_pub_panneau_detail_html").load( "https://tc610/ag_pub_collecte/Ag_pub_panneau_detail.html #ag_pub_panneau_detail_master_div");
    $("#ag_pub_panneau_detail_html").show();
});
因此,当我点击valider按钮时,我的div被加载并显示,到目前为止还不错

这就是我挣扎的地方,我试过这个:

if ($('ag_pub_panneau_detail_html').is(':visible')) {
    $('#ag_pub_panneau_entityid').val($('#ag_id_panneau').val());
}
但是div保持空白。所以我尝试了这个:

$("#valider").click(function() {
    $("#ag_pub_panneau_detail_html").load( "https://tc610/ag_pub_collecte/Ag_pub_panneau_detail.html #ag_pub_panneau_detail_master_div", fillDiv());
    $("#ag_pub_panneau_detail_html").show();
});

function fillDiv(){
    $('#ag_pub_panneau_entityid').val($('#ag_id_panneau').val());
}
但我得到了同样的结果。所以我尝试了别的方法:

$("#valider").click(function() {
    $("#ag_pub_panneau_detail_html").load( "https://tc610/ag_pub_collecte/Ag_pub_panneau_detail.html #ag_pub_panneau_detail_master_div");
    $("#ag_pub_panneau_detail_html").show();
    $('#ag_pub_panneau_entityid').val($('#ag_id_panneau').val());
});
我在想,既然.show运行良好,我可以在它下面添加我的行,但它似乎也无法执行

所以我过去认为这句话:

$('#ag_pub_panneau_entityid').val($('#ag_id_panneau').val());
是错误的,但当我从Chrome控制台执行它时,字段已正确填充。。。我不知道发生了什么,我对我的问题也没有想法

我做错什么了吗

如果您愿意,我可以提供更多代码/详细信息,请咨询我
任何帮助都将不胜感激

我设法让它工作起来,我所做的是为Ag_pub_panneau_detail.html页面创建了一个js文件,我刚才在其中写道:

$(document).ready(function() 
{

$('#ag_pub_panneau_entityid').val(localStorage.getItem("ag_pub_panneau_entityid"));

}); 
现在它就像一个符咒:

顺便问一下,我能知道为什么我对我的问题投了反对票吗


无论如何,谢谢你的帮助

您是否检查了控制台以确保AJAX请求正常工作?您可能被同一源策略阻止了。您是否有示例页面,这需要元素检查ag_pub_panneau_entityid是什么元素类型div没有value属性。您必须使用.text或.htmlinstead@RoryMcCrossan对不起,我的无知,但我该怎么做呢?我可以使用F12从chrome开发工具中看到它吗?可以-使用网络选项卡您可能被否决了,因为示例代码非常少,没有人可以看到发生了什么。