将$ j替换为JQuery [英] Replace $j with JQuery

查看:206
本文介绍了将$ j替换为JQuery的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个有趣的问题.我在Google chrome扩展程序中使用jQuery函数clone().该函数正在克隆表行.问题是TR使用$j()而不是jQuery()在其中包含一些内联javascript/jquery.

I am having an interesting issue. I am using the jQuery function clone() in a google chrome extension. The function is cloning a table row. The problem is that the TR has some inline javascript/jquery in it using $j() instead of jQuery().

每次尝试输出克隆的行时,都会出现错误"$ j未定义".

Every time I try to output the cloned row I get the error "$j is not defined".

因此,我想到了针对此问题的2种可能的解决方案:

So I thought of 2 possible solutions for this issue:

  1. 使我的chrome扩展程序与jQuery()$j()(使用jquery尝试,没有冲突)交互工作
  1. Make my chrome extension work with $j() (tried using jquery no conflict) intead of jQuery()

  1. 在输出克隆项目之前对其进行搜索,将$j替换为jQuery.
  1. Do a search in the cloned item before outputting it, replace $j with jQuery.

我的问题是我也无法完成...

My problem is that I cannot accomplish either...

 var rows = jQuery("#field-mapping-template").clone(true);
 rows.insertBefore("#field-mapping-template");

推荐答案

我的意思是,我不建议这样做,但是如果确实需要,可以 .

I mean, I wouldn't really recommend doing this but you can if you really need to.

进入jQuery的开发版本,一直向下滚动到底部,直到看到以下代码行:

Go into the development version of jQuery and scroll all the way down to the bottom until you see this line of code:

// Expose jQuery to the global object
window.jQuery = window.$ = jQuery;

现在只需将其更改为:

// Expose jQuery to the global object
window.jQuery = window.$j = jQuery;

现在,当您编写如下脚本时:

Now when you write a script like:

<input type="hidden" name="name" value="test" />
<script type="text/javascript">
    $j(function () {
        alert($j('input').val());
    });
</script>

代替$,它将适用于$j.

这与替换jQuery()不同. $jQuery()的简写.

This is different than replacing jQuery(). The $ is short hand for jQuery().

我真的,真的,真的不建议您用$ j或其他任何东西代替jQuery().

I would really, really, really not recommend replacing jQuery() with $j or anything for that matter.

从最新版本(v1.7.2)开始,开发代码中有 879个对jQuery对象的引用,您必须将其更改为$j.

As of the latest release (v1.7.2), there are 879 references to the jQuery object in the development code that you would have to change to $j.

如果您有很好的查找和替换方法,可以这样做,但我不建议这样做.

If you have a good find and replace, you can do it, but I would not recommend doing it.

这篇关于将$ j替换为JQuery的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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