我看到很多人在分配事件之前检查是否存在DOM元素,例如(coffeescript):
$ -> if( $("#progressbar").length > 0 ) $("#progressbar").progressbar( value: 0 )
这有必要吗?如果我们只是添加事件,无论元素是否存在,是否有性能损失?
javascript javascript-events coffeescript
coffeescript ×1
javascript ×1
javascript-events ×1