可以说我有以下html:
<div class="city">
<div class="building"></div>
<div class="street"></div>
<div class="house"></div>
</div>
<div class="city">
<div class="building"></div>
<div class="street"></div>
<div class="house"></div>
</div>
我想把所有东西都放在一个变量中,所以我可以这样做:
var city = $('.city'),
building = city.find('.building'),
street = city.find('.street'),
house = city.find('.house');
有没有另一种方法可以在变量中以某种方式使事情变得更容易?
var city = $('.city');
city[building = $('.building')];
city[street = $('.street')];
city[house = $('.house')];
所以我可以稍后以某种方式访问:
city[0]
或者
city[building]
?