假设我有这段代码:
$('#myBox').css('background', 'grey');
$('#myBox').click( function(e){ console.log( 'Box clicked' ); });
$('#myBox').html(' Just a test text ');
Run Code Online (Sandbox Code Playgroud)
到目前为止我所知道的是,我正在搜索myBox每行都带有ID 的元素.问题:当我有多个HTML元素引用时,我会从变量创建中受益吗?
或者,每次访问变量时,变量是否仍会搜索相关元素?例:
var $myBox = $('#myBox');
$myBox.css('background', 'grey');
$myBox.click( function(e){ console.log( 'Box clicked' ); });
$myBox.html(' Just a test text ');
Run Code Online (Sandbox Code Playgroud) 有没有一种方法可以在不克隆元素,不重排DOM,等待(setTimeout / onAnimationEnd)的情况下重新启动CSS动画?