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.
假设我在尝试查找元素时犯了一个错误并且我打错了,例如$('lsdkfj'). 我不想让 jQuery 返回一个空数组,而是想在控制台中返回一条错误消息,例如 "The selector 'lsdkfj' cannot be found". 这样做的最佳方法是什么?
$('lsdkfj')
"The selector 'lsdkfj' cannot be found"
像这样:
var oldInit = $.fn.init; $.fn.init = function(selector, context, rootjQuery) { var result = new oldInit(selector, context, rootjQuery); if (result.length === 0) console.info("jQuery call has no elements!", arguments); return result; };