JSFiddle包装在onLoad? [英] JSFiddle wrap in onLoad?
问题描述
我试图理解JSFiddle如何在'onLoad'中基于这个描述'包装'代码:
[1]: http://doc.jsfiddle.net/basic/introduction.html#javascript 。我已经看到onLoad被用在HTML的BODY标签中来加载函数。那么JSF(幕后)是如何包装每一个调用以及我在JS窗口中创建的每个函数? AKA:
onLoad =myfunc1(),myfunc2,alert(1);
如果是这样,那么当我选择jQuery作为框架时,我应该避免使用这种格式:
$ b $
$(document).ready(function(){
myfunc1 {(...)}
myfunc1 { (...)}
...
如果有骨架问题,请提前道歉。
它们将所有JS放入< script>
标签中例如,如果您选择包含jQuery和<$ c $> onLoad 事件代码,
< script type =text / conLoad
然后这就是jsfiddle的用法: javascript>
//<![CDATA [
$(window).load(function(){/ * your js here * /});
//]]> ;
如果您不包含库, :
< script type =text / javascript>
//<![CDATA [
window.onl oad = function(){/ *你的js在这里* /}
//]]>
< / script>
我假设他们也使用其他库特定的 load
使用 注意:要很好地解释 I'm trying to understand how JSFiddle 'wraps' code in 'onLoad' based on this description:
[1]: http://doc.jsfiddle.net/basic/introduction.html#javascript. I've seen onLoad being used in the HTML's BODY tag to load function(s). So does JSF (behind the scenes) wrap every call and every function I create int its JS window? AKA: If so then when I select jQuery as a framework, should I avoid using this format: Apologize in advance if an armature question. They put all your JS inside For example, if you choose to include jQuery and If you don't include a library then they use: I presume they also use other library specific Using Note: for a good explanation of what 这篇关于JSFiddle包装在onLoad?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋! $(document).ready(function(){}); $ c> $ c $>
CDATA
是看看这个答案 - https://stackoverflow.com/a/7092306/2287470 onLoad = "myfunc1(),myfunc2,alert(1);"
$(document).ready(function(){
myfunc1{(...)}
myfunc1{(...)}
...
<script>
tags with the onLoad
event code wrapped around it. onLoad
then this is what jsfiddle will use:<script type="text/javascript">
//<![CDATA[
$(window).load(function(){ /* your js here */ });
//]]>
</script>
<script type="text/javascript">
//<![CDATA[
window.onload=function(){ /* your js here */ }
//]]>
</script>
load
events depending on what you choose to include.$(document).ready(function(){ });
isn't required when running your code in a fiddle.CDATA
is take a look at this answer - https://stackoverflow.com/a/7092306/2287470