我继承了公司网站和仓促组装的 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;
};
我在这里缺少什么?
最佳答案
对我来说,只有新版本的 jQuery (1.7.1) 才会出现这种情况。如果我使用1.4.2,它不会报告任何错误。无论我使用哪种浏览器。
关于jQuery 和/或 markItUp! CTRL键窒息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7236075/