Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/398.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
Javascript 当我将HTML内容加载到div时,如何传递和检索一些数据?_Javascript_Html_Jquery - Fatal编程技术网

Javascript 当我将HTML内容加载到div时,如何传递和检索一些数据?

Javascript 当我将HTML内容加载到div时,如何传递和检索一些数据?,javascript,html,jquery,Javascript,Html,Jquery,当我将HTML内容加载到div时,如何传递和检索一些数据 例如: a、 html: <div id="topBar"> <a href ="#" id="load_home"> HOME </a> </div> <div id ="content"> </div> <script> $(document).

当我将HTML内容加载到div时,如何传递和检索一些数据

例如:

a、 html:

<div id="topBar">
    <a href ="#" id="load_home"> HOME </a>
</div>

<div id ="content">        
</div>

<script>
$(document).ready( function() {
    $("#load_home").on("click", function() {
        $("#content").load("b.html"); // HERE I want to pass datas, for example {firstname: "Peter", lastname: "Parker"}
    });
});
</script>

$(文档).ready(函数(){
$(“#加载#home”)。在(“单击”,函数()上{
$(“#content”).load(“b.html”);//这里我想传递数据,例如{firstname:“Peter”,lastname:“Parker”}
});
});
b、 html:

<p><b>firstname: </b></p> // I want to retrieve the data {firstname: "Peter", lastname: "Parker"} to fill the text
<p><b>lastname: </b></p> // I want to retrieve the data {firstname: "Peter", lastname: "Parker"} to fill the text
firstname:

//我想检索数据{firstname:“Peter”,lastname:“Parker”}来填充文本 lastname:

//我想检索数据{firstname:“Peter”,lastname:“Parker”}来填充文本
如何从a.html发送数据,如何在b.html中检索数据


也许我的想法是错误的

你写的是“从a.html发送我的数据,以及如何在b.html中检索它们”。也许你想把数据从b.html转换成a.html?还有什么不起作用?不知道你想要什么。。。但可能是异步JavaScript和XML