JSFiddle包装在onLoad? [英] JSFiddle wrap in onLoad?

查看:103
本文介绍了JSFiddle包装在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

使用 $(document).ready(function(){}); $ c $>

注意:要很好地解释 CDATA 是看看这个答案 - https://stackoverflow.com/a/7092306/2287470


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:

onLoad = "myfunc1(),myfunc2,alert(1);" 

If so then when I select jQuery as a framework, should I avoid using this format:

 $(document).ready(function(){
     myfunc1{(...)}
     myfunc1{(...)}
     ...

Apologize in advance if an armature question.

解决方案

They put all your JS inside <script> tags with the onLoad event code wrapped around it.

For example, if you choose to include jQuery and onLoad then this is what jsfiddle will use:

<script type="text/javascript">
    //<![CDATA[
        $(window).load(function(){ /* your js here */ });
    //]]>
</script>

If you don't include a library then they use:

<script type="text/javascript">
    //<![CDATA[
        window.onload=function(){ /* your js here */ }
    //]]>
</script>

I presume they also use other library specific load events depending on what you choose to include.

Using $(document).ready(function(){ }); isn't required when running your code in a fiddle.

Note: for a good explanation of what CDATA is take a look at this answer - https://stackoverflow.com/a/7092306/2287470

这篇关于JSFiddle包装在onLoad?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆