jquery 里面load方法 为什么不能加载js呢 怎么样才能解决呢 js要放在一个单独的js文件中
首先你要确定你想要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" );