gpt4 book ai didi

javascript - 从文件 html 加载脚本标签

转载 作者:行者123 更新时间:2023-11-30 12:42:55 25 4
gpt4 key购买 nike

在第一页的页眉

<script type="text/javascript">
$(document).ready(function(){
$("#register_reg").click(function(){
$("#register_form").load("test_test.php #register_rules");
});
});
</script>

在第二个文件(test_test.php)中ID#register_rules的内容有这条线

<script type="text/javascript" src="jquerycode.js"></script>

问题是,在第一个页面中,当我单击链接 (ID #register_reg) 时,script 行未添加到 ID #register_form

那么,我如何在 ID #register_form 中添加 ID #register_rules 的内容

最佳答案

脚本从加载的 HTML 中剥离。

来自关于 load() 的 jQuery 文档(添加了重点)

http://api.jquery.com/load/

Script Execution

When calling .load() using a URL without a suffixed selector expression, the content is passed to .html() prior to scripts being removed. This executes the script blocks before they are discarded. If .load() is called with a selector expression appended to the URL, however, the scripts are stripped out prior to the DOM being updated, and thus are not executed. An example of both cases can be seen below:

Here, any JavaScript loaded into #a as a part of the document will successfully execute.

1 $( "#a" ).load( "article.html" ); However, in the following case, script blocks in the document being loaded into #b are stripped out and not executed:

1 $( "#b" ).load( "article.html #target" );

关于javascript - 从文件 html 加载脚本标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23747390/

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