变量名前的美元符号或没有美元符号 [英] Dollar sign in front of a variable name or no dollar sign
问题描述
我正在阅读Scott Allen的有关ASP.NET MVC的教程.我到了一些使用jQuery的代码的部分.
I'm going through Scott Allen's tutorial about ASP.NET MVC. I got to the section where there is some code that uses jQuery.
$(function () {
var ajaxFormSubmit = function () {
var $form = $(this);
var options = {
url: $form.attr("action"),
type: $form.attr("method"),
data: $form.serialize()
};
$.ajax(options).done(function (data) {
var $target = $($form.attr("data-otf-target"));
var $newHtml = $(data);
$target.replaceWith($newHtml);
$newHtml.effect("highlight");
});
return false;
};
我试图了解带有或不带有美元符号的变量之间的区别.例如,变量form
具有美元符号,而options
没有美元符号,那么ajax done
部分中的变量也具有美元符号.
I'm trying to understand what's the difference between the variables with or without the dollar signs. For example variable form
has a dollar sign and the options
does not and then the variables inside the ajax done
part also have the dollar signs.
在我们使用jQuery的系统中,我没有看到这样的代码.有什么区别?这与ASP.NET MVC 4和/或新版本的jQuery有关吗?
In our system where we use jQuery I haven't seen such code. What is the difference? Is this has something to do with the ASP.NET MVC 4 and/or the new versions of jQuery?
推荐答案
$
在JavaScript标识符中没有特殊含义.
$
has no special meaning in a JavaScript identifier.
有一个惯例可以使用以$
字符开头的变量名来表示将包含jQuery对象的变量.
There is a convention to use a variable name starting with a $
character to represent a variable that will hold a jQuery object.
这篇关于变量名前的美元符号或没有美元符号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!