简体   繁体   English

如何找到jQuery错误的来源?

[英]How to find the source of the jQuery error?

I have a page which references jQuery 3.3.1, jQuery-Migrate 1.4.1 and Bootstrap 3.3.7.我有一个引用 jQuery 3.3.1、jQuery-Migrate 1.4.1 和 Bootstrap 3.3.7 的页面。 When I click anywhere on the page, I get the following error in the console:当我单击页面上的任意位置时,控制台中出现以下错误:

jquery-3.3.1.js?v=2018.8.0.1-develop:1541 Uncaught Error: Syntax error, unrecognized expression: #
    at Function.Sizzle.error (jquery-3.3.1.js?v=2018.8.0.1-develop:1541)
    at Sizzle.tokenize (jquery-3.3.1.js?v=2018.8.0.1-develop:2193)
    at Sizzle.select (jquery-3.3.1.js?v=2018.8.0.1-develop:2620)
    at Function.Sizzle (jquery-3.3.1.js?v=2018.8.0.1-develop:845)
    at Function.a.find (jquery-migrate-1.4.1.min.js?v=2018.8.0.1-develop:2)
    at jQuery.fn.init.find (jquery-3.3.1.js?v=2018.8.0.1-develop:2873)
    at jQuery.fn.init.a.fn.find (jquery-migrate-1.4.1.min.js?v=2018.8.0.1-develop:2)
    at a.fn.init.jQuery.fn.init (jquery-3.3.1.js?v=2018.8.0.1-develop:2983)
    at new a.fn.init (jquery-migrate-1.4.1.min.js?v=2018.8.0.1-develop:2)
    at jQuery (jquery-3.3.1.js?v=2018.8.0.1-develop:139)

From the error unrecognized expression: # , it's clear to me that there is code like below, where the variable is either blank/null/undefined:从错误unrecognized expression: # ,我很清楚有如下代码,其中变量是空白/空/未定义:

$('#' + someBlankVariable).method();

I searched for '#' + and placed breakpoints on all found instances and none of them are getting hit with a blank variable.我搜索了'#' +并在所有找到的实例上放置了断点,并且它们都没有被空白变量击中。

So, given that the entire error stack is in jQuery and jQuery-migrate, how can I determine what is actually causing the error?因此,鉴于整个错误堆栈都在 jQuery 和 jQuery-migrate 中,我如何确定实际导致错误的原因?

It generating cause of the following attribute:它产生以下属性的原因:

href="#"

Replacing it with the attribute用属性替换它

href="javascript:void(0)"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM