我最近升级了PHPStorm IDE的版本,它现在警告我使用jQuery不够高效。
例如:
var property_single_location = $("#property [data-role='content'] .container");
引发以下警告:
检查jQuery选择器的使用效率。它建议拆分以ID选择器为前缀的后代选择器,并警告可能被缓存的重复选择器。
那么我的问题是:
为什么这是低效的,以及执行上述选择器的高效方法是什么?
我猜测的方法是:
var property_single_location = $("#property").find("[data-role='content']").find(".container");
这样做正确吗?