简体   繁体   English

jQuery BBQ使用jQuery 2生成错误

[英]jQuery BBQ generates error with jQuery 2

jQuery BBQ noob question: I have downloaded jQuery BBQ 1.2.1 and I'm trying to use it with jQuery 2.1.0. jQuery BBQ noob问题:我已经下载了jQuery BBQ 1.2.1,我正在尝试将它与jQuery 2.1.0一起使用。 BBQ works in the sense that it does what I want it to do, but I've noticed an error message in the console. 烧烤工作的意义在于它做了我想做的事情,但我注意到控制台中有一条错误信息。 I've tracked it down to what appears to be a compatibility issue. 我已将其跟踪到似乎是兼容性问题。 Here's a sample HTML page that produces the error: 这是一个产生错误的示例HTML页面:

<!DOCTYPE HTML>
<html>
    <head>
        <title>example</title>
    </head>
    <body>
        example
    </body>
    <script src="../js/lib/jquery-2.1.0.min.js"></script>
    <script src="../js/lib/jquery.ba-bbq.min.js"></script>
</html>

In Firefox the console error is TypeError: f is undefined . 在Firefox中,控制台错误是TypeError: f is undefined In Chrome the error is different: Uncaught TypeError: Cannot read property 'msie' of undefined . 在Chrome中,错误有所不同: Uncaught TypeError: Cannot read property 'msie' of undefined

I've noticed jQuery BBQ is pretty old. 我注意到jQuery BBQ很老了。 Is there a newer rev of jQuery BBQ? 是否有更新的jQuery BBQ版本? Or is there some newer replacement library? 或者是否有更新的替换库?

UPDATE UPDATE

I'm using jQuery BBQ because a google search sent me to this previously answered question: Parsing URL hash/fragment identifier with JavaScript . 我正在使用jQuery BBQ,因为谷歌搜索发送给我之前回答的问题: 使用JavaScript解析URL散列/片段标识符 The real issue I'm trying to solve is the same as the linked question: to respond to changes in the hash portion of the URI and to parse that fragment. 我试图解决的真正问题与链接问题相同:响应URI的哈希部分中的更改并解析该片段。

It turns out that for my purposes (so far), I can eliminate jQuery BBQ and write a couple of lines of code to grab the hash string (and remove the hash sign): 事实证明,就我的目的而言(到目前为止),我可以消除jQuery BBQ并编写几行代码来获取哈希字符串(并删除哈希符号):

    $(window).bind('hashchange', function() {
        var hashString = window.location.hash || '';
        hashString = hashString.replace("#",'');
        myEventHandler(hashString);
    });

So that will work for now. 这样就可以了。 It's pretty simple and it's one less module dependency, so win-win. 它非常简单,它减少了模块依赖性,因此是双赢的。 I suppose that's why there were no responses to a jQuery-BBQ question, eh? 我想这就是为什么对jQuery-BBQ问题没有回应,是吗?

I am glad that your problem was solved(1 year ago!). 我很高兴你的问题解决了(1年前!)。 But for anybody else who has this problem: 但对于遇到此问题的其他人:

As you may have seen in this answer this problem is caused by $.browser which was deprecated in version 1.3 and removed in 1.9. 正如您在此答案中看到的那样, 问题是由$ .browser引起的,该版本在1.3版中已弃用,在1.9中已删除。

but you can fix that quite simply. 但你可以很简单地解决这个问题。 just open jquery bbq source and search for f.msie (used like h = f.msie ) and replace it with: 只需打开jquery bbq源并搜索f.msie(像h = f.msie一样使用)并将其替换为:

( navigator.appName == 'Microsoft Internet Explorer') ? true : false

(now you must have h = ( navigator.appName == 'Microsoft Internet Explorer') ? true : false ) (现在你必须有h = ( navigator.appName == 'Microsoft Internet Explorer') ? true : false

The syntax that worked for me was: 对我有用的语法是:

h = ( navigator.appName == 'Microsoft Internet Explorer' ? true : false)

or if used as part of an "if" switch... 或者如果用作“if”开关的一部分......

 (h = ( navigator.appName == 'Microsoft Internet Explorer' ? true : false))

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

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