code工作在的jsfiddle,但不是在我的应用程序 [英] Code works in jsfiddle but not in my application

查看:92
本文介绍了code工作在的jsfiddle,但不是在我的应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道,如果comebody可以做我一个大忙,在我的jsfiddle它显示在我的应用程序的整个code。现在,如果你点击链接(开放网格),然后选择一个按钮,它会显示以下按钮的右边数。例如,如果用户选择按钮1时,将显示按钮A,如果有人选择按键2,那么它​​会显示按钮A和B等等等等。我的问题是,它工作在的jsfiddle但它并不在我的应用程序工作,(我用深红编辑器)。我想知道,如果有人可以在自己的文本编辑器或Web编程软件复制此code,看看是否他们的网页上工作,因为我的应用程序从网格中选择一个按钮后,不显示下面的按钮。你能不能让我知道如果它工作或没有,谢谢你。

I want to know if comebody can do me a big favour, in my jsfiddle it shows the whole code in my application. Now if you click on the link (Open Grid) and select a button, it would displays the right number of buttons below. E.G if user selects button "1", it would display button "A", if somebody selects button "2", then it would display buttons "A" and "B" and so on and so on. My problem is that it works in jsfiddle but it does not work in my app, (I am using Crimson Editor). I am wondering if somebody can copy this code in their text editor or web programming software and see if it work on their page because in my application it does not display the buttons below after selecting a button from the grid. Can you let me know if it works or not, thank you.

我的code是这里

推荐答案

当您要访问的DOM元素,你应该domready中事件发生后做到这一点。由于有可能同时执行脚本的元素不存在。

When you want to access any DOM element, you should do it after domready event. As it might be possible while script execution that element doesn't exist.

因此​​,任何DOM相关功能,如 $(elementid)应该只domready中事件后使用。对于这样的Jquery提供 $。就绪()功能。

So any DOm related function such as $("elementid") should be used only after domready event. For doing this Jquery provide $.ready() function.

所以,如果你把里面的 $所有code。就绪(),它会正常工作。

So, if you put all your code inside $.ready(), it will work correctly.

这是在工作的jsfiddle,因为你已经选择了放在body标签的JavaScript(注意不裹体)。因此,加载网页时它会被执行。

It was working in Jsfiddle, because you have selected to place JavaScript in body tag (notice no wrap body). So it will get executed when webpage is loaded.

链接到更正code

这篇关于code工作在的jsfiddle,但不是在我的应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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