-8

I just started using jQuery and I love it. Don't know how I lived without it.

I started off small by doing some basic showing and hiding, and fading in, then fading back out. It works great.

My problem occurs when I decided to use the "&" symbol for my jQuery variables instead of the normal "$" (isn't that right?). I don't really like the look of the $ sign as it reminds my of my mortgage payment thats 3 months overdue. But I had to have this new MacBook Pro retina display...anyway I diverge.

So I'm trying to do basic stuff using the &, like so:

&('body').show('superfast');

But it's not working. I also tried to make all of the blink tags on my page blink twice as fast like this:

&('blink').animate({
    'speed': 'faster'
})

Lastly when the user puts their mouse over any of the images on my web page I want to play a cat sound...my website sells massage therapy sessions for dogs and the cat sound will probably make them happy right? I tried this:

&('image').mouseover(function(){
    var audio = new Audio("noise.mp3");
    audio.play();
});

Can somebody help me please? I really don't want to use the $ because it makes me realize all of the money I'm losing from my webpage until this code runs. Help?

4

4 回答 4

5

$用作函数引用的原因是jQuery它很短,也不是保留符号。

&符号不起作用,因为它是为按位与运算保留的,因此不能用作变量名。

您的选择是jQuery直接使用该功能,例如:

jQuery(function () { ... });

或使用$如:

$(function () { ... });

您还可以分配其他内容,例如:

var _ = jQuery;

或者

var IHateDollarSign = jQuery;

只要不保留标识符。

于 2012-08-31T19:15:18.167 回答
4

您可以使用“jQuery”而不是“$”

$('body').show('superfast');

是相同的

jQuery('body').show('superfast');
于 2012-08-31T19:08:06.243 回答
0

我不认为你正在尝试做的是一个好主意。你不应该改变它。

于 2012-08-31T19:10:20.507 回答
0

您可以只使用随机字符。JQuery 将自身映射到 $。你可以通过简单地将jQuery对象分配给类似'q'的东西来映射它,方法是这样写:var q = window.jQuery;

于 2012-08-31T19:10:28.563 回答