jQuery 和/或 markItUp! CTRL键窒息

发布于 2024-12-02 12:11:55 字数 1903 浏览 2 评论 0原文

我继承了该公司的网站和一个仓促组装的 CMS。今天遇到了第一个错误,我被难住了。

CMS 使用 markItUp!,我以前从未听说过。问题是这样的:每当有人在受影响的文本区域中键入CTRL字符时,jQuery就会抛出一个可爱的语法错误,无法识别的表达式:[ctrl字符]异常。

我正在看 markItUp! keyPressed 函数,我不知道在这种情况下它会如何工作。要使用快捷键,您必须在它们前面加上 CTRL,但 keyPressed 始终会在您按下 CTRL 后触发,而在集合中找不到 CTRL,因此 Sizzle.filter 中出现错误。

在文本区域处于焦点的情况下按 CTRL,然后:

//jquery.markitup.js

    function keyPressed(e) { 
       shiftKey = e.shiftKey;
       altKey = e.altKey;
       ctrlKey = (!(e.altKey && e.ctrlKey)) ? e.ctrlKey : false;

       if (e.type === 'keydown') {
          if (ctrlKey === true) {
             //Line below attempts to find an anchor tag with accesskey CTRL character
             li = $("a[accesskey="+String.fromCharCode(e.keyCode)+"]", header).parent('li');
             //SNIP
          }
       }
    }


    //jquery-1.5.js

    Sizzle.filter = function( expr, set, inplace, not ) {
       var count = 0;
       var match, anyFound,
          old = expr,
          result = [],
          curLoop = set,
          isXMLFilter = set && set[0] && Sizzle.isXML( set[0] );

       //expr = the CTRL character, set = the markItUp! default set
       while ( expr && set.length) {
          for ( var type in Expr.filter ) {
             if ( (match = Expr.leftMatch[ type ].exec( expr )) != null && match[2] ) {
                //SNIP
             }
          }

          // Improper expression
          if ( expr === old ) {
             if ( anyFound == null ) {
                Sizzle.error( expr );
             } else {
               break;
             }
          }

          old = expr;
       }
       return curLoop;
    };

    Sizzle.error = function( msg ) {
       throw "Syntax error, unrecognized expression: " + msg;
    };

我在这里缺少什么?

I've inherited the company website and a hastily thrown together CMS along with it. Got my first bug today and I'm stumped.

The CMS uses markItUp!, which I'd never heard of before. The problem is this: whenever someone types the CTRL character into the affected textarea, jQuery throws a lovely Syntax error, unrecognized expression: [ctrl character] exception.

I'm looking at the markItUp! keyPressed function and I don't see how it would ever work, under the circumstances. To use the shortcuts, you must preface them with CTRL, but keyPressed will always fire after you press CTRL, not find CTRL in the set, hence error in Sizzle.filter.

Press CTRL with textarea in focus, then:

//jquery.markitup.js

    function keyPressed(e) { 
       shiftKey = e.shiftKey;
       altKey = e.altKey;
       ctrlKey = (!(e.altKey && e.ctrlKey)) ? e.ctrlKey : false;

       if (e.type === 'keydown') {
          if (ctrlKey === true) {
             //Line below attempts to find an anchor tag with accesskey CTRL character
             li = $("a[accesskey="+String.fromCharCode(e.keyCode)+"]", header).parent('li');
             //SNIP
          }
       }
    }


    //jquery-1.5.js

    Sizzle.filter = function( expr, set, inplace, not ) {
       var count = 0;
       var match, anyFound,
          old = expr,
          result = [],
          curLoop = set,
          isXMLFilter = set && set[0] && Sizzle.isXML( set[0] );

       //expr = the CTRL character, set = the markItUp! default set
       while ( expr && set.length) {
          for ( var type in Expr.filter ) {
             if ( (match = Expr.leftMatch[ type ].exec( expr )) != null && match[2] ) {
                //SNIP
             }
          }

          // Improper expression
          if ( expr === old ) {
             if ( anyFound == null ) {
                Sizzle.error( expr );
             } else {
               break;
             }
          }

          old = expr;
       }
       return curLoop;
    };

    Sizzle.error = function( msg ) {
       throw "Syntax error, unrecognized expression: " + msg;
    };

What am I missing here?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

梦纸 2024-12-09 12:11:55

对我来说,只有新版本的 jQuery (1.7.1) 才会出现这种情况。如果我使用1.4.2,它不会报告任何错误。无论我使用哪种浏览器。

For me it only happens with a new version of jQuery (1.7.1). If I use 1.4.2, it doesn't report any error. No matter which browser I use.

雪落纷纷 2024-12-09 12:11:55

该问题已通过此提交中的 jquery 1.5 兼容性补丁得到修复。

补丁中的相关行是:

-            li = $("a[accesskey="+String.fromCharCode(e.keyCode)+"]", header).parent('li');
+            li = $('a[accesskey="'+String.fromCharCode(e.keyCode)+'"]', header).parent('li');

The problem has been fixed with the jquery 1.5 compatibility patch in this commit.

The relevant line in the patch was:

-            li = $("a[accesskey="+String.fromCharCode(e.keyCode)+"]", header).parent('li');
+            li = $('a[accesskey="'+String.fromCharCode(e.keyCode)+'"]', header).parent('li');
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文