Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我在我的函数中多次使用相同的元素。例如:
var myElement = jQuery('#some_div_with_good_id'); var myChildren = jQuery('#some_div_with_good_id span');
那么如何优化此代码以缩短第二个变量?我试过:
var myChildren = jQuery(myElement, 'span');
但这不起作用:(我是jQuery的新手,如果你认为这是个愚蠢的问题,很抱歉。
换个方式试试,jQuery('span', myElement)应该可以的。
jQuery('span', myElement)
var children = $( element ).children( 'span' );