在 $. kick ()
函数之后无法重新声明 $. (this)
吗? 因为这些功能似乎都行不通 :
$(this) = $(this).find( span );
var $(this) = $(this).find( span );
在 $. kick ()
函数之后无法重新声明 $. (this)
吗? 因为这些功能似乎都行不通 :
$(this) = $(this).find( span );
var $(this) = $(this).find( span );
当foo
是一个合法的识别符 时,您只能声明 var foo
。
$( this)
是 调用 函数的结果, 该函数命名为 $
, 带有参数 this
因此在声明中不合法 。
您也不应该覆盖 < code> this code > -- -- 这将在未来引起很大的头部抓伤!!
如果您想要存储 jQuery 版本 this
的本地变量, 普通公约为 :
var $this = $(this);
var $span = $this.find( span );
当 $
前缀允许您记住变量是jQuery 对象,而不是普通的 DOM 元素时,该变量(完全合法,但有时被扭曲) $
前缀允许您记住该变量是一个 jQuery 对象。
该公约还允许你发现这样做的浪费(但常见)错误:
var jqobj = $(myobj)
当 myobj
是 已经 a jQuery 对象时 。
$( This)
表达式不是一个变量声明,而是一个表达式。 如果您想要重新声明某个您需要将其存储在变量中的东西, 则该表达式是一个表达式。
var saved = $(this);
saved = $(this).find( span );
最终版本之所以有效,是因为您正在将它指派给一个实际的标识符。
$( some ).on( click , function() {
var refrence = $(this);
var span = refrence.find( span )
// to override the $this you can use
refrence = refrence.find( span );
});
So, I using this snippet <tr onclick="this.toggleClassName( selected )"> on a web page. (a Prototype.js function) It works great. All I do is click on a table row, and it appears to get ...
I have a listener inside Class A, and I want to pass Class A to my Class B inside the listener. Normally I d just use this, but then I d get the event that triggered the listener.
I am not very sure with the use of "this" [current context] in jquery.What I know is- it prevents the dom from searching all the elements, it just work on that current element, which improve ...
I m writing an online game which allows a user to progress from one puzzle to the next, and if the user makes mistakes, each puzzle has a start again button to allow the user to start just that puzzle ...
I am (slowly) writing an XML parser for some "site definition" files that will drive a website. Many of the elements will be parsed in the same manner and I won t necessarily need to keep the values ...
Is there a difference between the two codes below, I presume not. function Agent(bIsSecret) { if(bIsSecret) this.isSecret=true; this.isActive = true; this.isMale = false; } and ...
Does anybody know? Couldn t find this question asked before, even though it seems fairly basic.
One of the built-in Checkstyle checks is RequireThis, which will go off whenever you don t prepend this. to local field or method invocations. For example, public final class ExampleClass { ...