如何在firefox插件中使用jQuery? [英] How do I use jQuery in firefox addon?

查看:181
本文介绍了如何在firefox插件中使用jQuery?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的Firefox扩展的边栏中使用jQuery。这是我如何在sidebar.xul中包含jQuery

$ p $ lt; code>< script type =application / x-javascriptsrc = chrome:// myaddon / content /
scripts / jquery / js / jquery-1.4.4.min.js/>

< script type =text / javascript> jQuery.noConflict();< / script>

第一个问题,为什么我们使用 jQuery.noConflict() code> function?



我尝试了其他一些问题的解决方案,但是这对我没有任何作用。

 < script type =application / x- javascript
src =chrome://myextension/content/scripts/jquery/js/jquery-1.4.4.min.js/>
< script type =text / javascript>
jQuery.noConflict();
jQuery(document).ready(function(){
alert(hello);
});
< / script>


解决方案

当你包含其他库如prototype,mootools,YUI问题出现在一个或多个这些库与jQuery一起使用时,因为它们也使用$()作为其全局函数并定义变量。这种情况会产生冲突,因为$()被jQuery和其他库用作其全局函数。为了克服这种情况,jQuery引入了jQuery.noConflict()。

所以你可以基本上做

pre> var $ j = jQuery.noConflict();

现在您可以使用 $ j()而不是 $()



至于firefox插件,我假设你指的是萤火虫。您在jquery中输入的区域称为控制台。您可以阅读更多 http://getfirebug.com/commandline




I want to use jQuery in the sidebar of my firefox extension. This is how I include jQuery in the sidebar.xul

  <script type="application/x-javascript" src="chrome://myaddon/content/
  scripts/jquery/js/jquery-1.4.4.min.js"/>

  <script type="text/javascript">jQuery.noConflict();</script>

First question, why do we use the jQuery.noConflict() function?

I tried the solutions of some other questions but it did not work for me.

Still this does not work for me on FF 3.6.13:

<script type="application/x-javascript" 
       src="chrome://myextension/content/scripts/jquery/js/jquery-1.4.4.min.js"/>
  <script type="text/javascript">
    jQuery.noConflict();
    jQuery(document).ready(function () {
        alert("hello");
    });
 </script>

解决方案

When you include other libraries like prototype, mootools, YUI etc, The problem comes when one or more of those libraries are used with jQuery as they also use $() as their global function and to define variables. This situation creates conflict as $() is used by jQuery and other library as their global function. To overcome from such situations, jQuery has introduced jQuery.noConflict().

So you can basically do

 var $j = jQuery.noConflict();

Now you can write jQuery command using $j() instead of $()

As for the firefox plugin, I'm assuming you are referring to firebug. The area where you type in your jquery is called console. You can read more at http://getfirebug.com/commandline

这篇关于如何在firefox插件中使用jQuery?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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