怎么样才能让jquery load 加载的页面中的js加载呢?

JavaScript010

怎么样才能让jquery load 加载的页面中的js加载呢?,第1张

query的load方法加载的网页里面的js不是被加载的页面里面导js,而是在当前页导入,举个例子:

a.htm页调用load方法加载b.htm,b.htm里有js,那么应在a.htm里面导入该js,载入b.htm后操作该js就像在a.htm里操作一样。

首先你要确定你想要load的页面中,script标签放到哪里了?

如果放倒head里面是不行的,你的script标签必需放倒body里面。

此外,

$('#container').load('./ajaxload.html#ctn')

这种方式也是不行的。因为只解析了ctn里的内容

jquery文档里给了如下说明:

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" )