javascript 如何用jquery中使用的另一个字符替换“美元”符号?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20348840/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-27 18:17:10  来源:igfitidea点击:

how to replace 'dollar' sign with another character used in jquery?

javascriptjquery

提问by user2609417

How will I change the dollar sign (alias for 'jquery') used in jquery with another character. For example

我将如何将 jquery 中使用的美元符号('jquery' 的别名)更改为另一个字符。例如

$("#id").css("height","210px");

I want to change this to

我想把它改成

*("#id").css("height","210px");

回答by georg

You cannot change $to *because *is not a valid identifier. But you can change it to a valid one:

您不能更改$为,*因为*它不是一个有效的标识符。但是您可以将其更改为有效的:

(function (foobar) {
    foobar("#whatever").css(....)


})(jQuery);

Given that JavaScript identifiers are unicode, you can try fancy thingslike for example:

鉴于JavaScript 标识符是 unicode,您可以尝试一些奇特的事情,例如:

(function (Ω) {
    Ω("#whatever").css(....)
})(jQuery);

回答by Rituraj ratan

dont use *as a variable name please choose valid name here i choose js

不要*用作变量名称,请在此处选择有效名称,我选择js

var js =jQuery.noConflict(); //by this you can do it

reference jQuery.noConflict()

参考jQuery.noConflict()

回答by Richard Parnaby-King

jQuery comes with a noConflictcommand which you can assign to a custom variable:

jQuery 附带一个noConflict命令,您可以将其分配给自定义变量:

var jq = jQuery.noConflict(true);

This means you can do regular jQuery with your symbol:

这意味着您可以使用您的符号执行常规 jQuery:

jq.css('height', '200px');

You cannot use the asterisk (*) because it is a reserved character.

不能使用星号 (*),因为它是保留字符。