我有这段代码:
<script src="http://code.jquery.com/jquery-2.2.2.min.js"></script>
<!-- start feedwind code -->
<!-- select protocol http or https -->
<script type="text/javascript">
$.holdReady(true);
$.getScript("http://feed.mikle.com/js/rssmikle.js",
function() { $.holdReady(false); });
console.log( "Load was performed." );
</script>
<!--<script type="text/javascript" src="http://feed.mikle.com/js/rssmikle.js"></script>-->
<script type="text/javascript">
var params = {
rssmikle_url: "http://althouse.blogspot.com",
rssmikle_frame_width: "400",
rssmikle_frame_height: "400",
frame_height_by_article: "3",
rssmikle_target: "_blank",
rssmikle_font: "Arial, Helvetica, sans-serif",
rssmikle_font_size: "12",rssmikle_border: "off",
responsive: "off",rssmikle_css_url: "",
text_align: "left",
text_align2: "left",
corner: "off",
scrollbar: "on",
autoscroll: "on",
scrolldirection: "up",
scrollstep: "3",
mcspeed: "20",
sort: "Off",
rssmikle_title: "on",
rssmikle_title_sentence: "",
rssmikle_title_link: "",
rssmikle_title_bgcolor: "#0066FF",
rssmikle_title_color: "#FFFFFF",
rssmikle_title_bgimage: "",
rssmikle_item_bgcolor: "#FFFFFF",
rssmikle_item_bgimage: "",
rssmikle_item_title_length: "55",
rssmikle_item_title_color: "#0066FF",
rssmikle_item_border_bottom: "on",
rssmikle_item_description: "on",
item_link: "off",
rssmikle_item_description_length: "150",
rssmikle_item_description_color: "#666666",
rssmikle_item_date: "gl1",
rssmikle_timezone: "Etc/GMT",
datetime_format: "%b %e, %Y %l:%M %p",
item_description_style: "text+tn",
item_thumbnail: "full",
item_thumbnail_selection: "auto",
article_num: "15",
rssmikle_item_podcast: "off",
keyword_inc: "",
keyword_exc: ""
};
(function(params) {
console.log( "Function started" );
feedwind_show_widget_iframe(params);
}
)(params);</script>
<div style="font-size:12px; text-align:center; width:300px;">
<a href="http://feed.mikle.com/" target="_blank" style="color:#CCCCCC;">RSS Feed Widget</a>
<!--Please display the above link in your web page according to Terms of Service.--></div>
<!-- end feedwind code --><!-- end feedwind code -->
它应该从mikle.com加载RSS,所以你应该看到帖子列表。我想使用Jquery加载脚本。我用$ .holdReady(true);所以函数feedwind_show_widget_iframe(params);在下载脚本之前不应该调用它。此外,我在控制台中看到日志已加载文件,然后调用该函数。如果我用mikel的RSS取消注释脚本标签,那么一切正常,但我想动态加载它。
答案 0 :(得分:1)
当您致电getScript
时,您会在脚本加载后向其传递回调(function() { $.holdReady(false); }
)以执行。
您已经放置了依赖于该脚本的代码,因此它在您开始请求脚本后立即运行,而不是在脚本可用后运行的回调内部运行。