jQuery-用$ this代替$(this)? [英] jQuery - $this instead of $(this)?
本文介绍了jQuery-用$ this代替$(this)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我认为我读到的东西说这样对这样的代码更好:
I think that i read something that said that it is better for code like this:
var id1 = $(this).attr('id')
var id2 = $(this).parent().parent().parent().parent().parent().attr('id')
var text = $(this).text()
..给出一个像$this = $(this)
这样的变量,然后代替每个$(this)使用它.我不知道我在哪里读的书,所以我的问题是真的吗?
..to give one variable like $this = $(this)
and then use it instead of every $(this). I don't know where i read this, so my question is that is it true?
推荐答案
是的
var $this = $(this);
var id1 = $this.attr('id');
var id2 = $this.parent().parent().parent().parent().parent().attr('id') ;
var text = $this.text();
这篇关于jQuery-用$ this代替$(this)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文