【发布时间】:2016-03-20 00:05:50
【问题描述】:
页面 1 有一个 ID 为 (#navigation) 的菜单,一个名为 Page2 的链接和一个 ID 为 (global_content) 的 DIV,当点击链接 Page2 时显示内容。在同一页面(第 1 页)中,我编写了一个 jquery 加载函数,这样当我单击链接时,它应该显示内容而无需重新加载页面。加载事件工作正常,显示内容,但没有 Page 2 具有的脚本标签。
这是第 1 页中的代码
<script>
jQuery(document).ready(function() {
//jQuery('#navigation li a').click(function(){
jQuery('#navigation li').on('click', 'a', function(){
var toLoad = jQuery(this).attr('href')+' #global_content';
jQuery('#global_content').fadeOut('fast',loadContent);
jQuery('#load').remove();
jQuery('#wrapper').append('<span id="load">LOADING...</span>');
jQuery('#load').fadeIn('normal');
function loadContent() {
jQuery('#global_content').load(toLoad, function() {
jQuery('#global_content').fadeIn('fast', hideLoader());
});
}
function showNewContent() {
jQuery('#global_content').show('normal',hideLoader());
}
function hideLoader() {
jQuery('#load').fadeOut('normal');
}
return false;
});
}); </script>
这是第 2 页中的代码
<div id="wall-feed-scripts">
<script type="text/javascript">
Wall.runonce.add(function () {
var feed = new Wall.Feed({
feed_uid: 'wall_91007',
enableComposer: 1,
url_wall: '/widget/index/name/wall.feed',
last_id: 38,
subject_guid: '',
fbpage_id: 0 });
feed.params = {"mode":"recent","list_id":0,"type":""};
feed.watcher = new Wall.UpdateHandler({
baseUrl: en4.core.baseUrl,
basePath: en4.core.basePath,
identity: 4,
delay: 30000,
last_id: 38,
subject_guid: '',
feed_uid: 'wall_91007'
});
try {
setTimeout(function () {
feed.watcher.start();
}, 1250);
} catch (e) {
}
});
</script>
</div>
<div class="wallFeed">
some content
</div>
但我得到的输出是
<div id="wall-feed-scripts"></div>
<div class="wallFeed">
some content
</div>
你能帮忙吗?
【问题讨论】:
-
这是设计使然,
<scripts>未加载/执行。 -
你会想要使用
$.getScript() -
@JayBlanchard,但 getScripts() 意味着我必须将 js 脚本放在文件 .js 中
-
所以?那有什么问题?你应该尽可能地分开你的代码。
标签: javascript jquery html jquery-load