&引用;属性(id)特殊检查失败“;jQuery
我从控制台收到此消息: 属性(id)特殊检查失败,而不是通过访问属性&引用;属性(id)特殊检查失败“;jQuery,jquery,Jquery,我从控制台收到此消息: 属性(id)特殊检查失败,而不是通过访问属性 属性(id),请使用未定义 我的代码非常简单: $(document).ready(function(){ var sezione = ""; $('.menu_bar').click(function() { sezione = $(this).attr('id'); }); }); 有什么问题吗 编辑 这是我的页面中的html: <html xmlns="http://www
属性(id),请使用未定义 我的代码非常简单:
$(document).ready(function(){
var sezione = "";
$('.menu_bar').click(function() {
sezione = $(this).attr('id');
});
});
有什么问题吗
编辑
这是我的页面中的html:
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="stylesheet" type="text/css" href="/css/glamStyle2.css" />
<script src="http://www.modernizr.com/downloads/modernizr-latest.js"></script>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js"></script>
<script language="javascript" type="text/javascript" src="/js/jquery.easing.1.3.js"></script>
<!--[if IE]><script src="excanvas.js"></script><![endif]-->
<script src="/js/jquery.jsPlumb-1.3.1-all-min.js"></script>
<script language="javascript" type="text/javascript" src="/js/floating2.js"></script>
<title>Glam Group srl</title>
</head>
<body>
<div id="container">
<div id="top_bar" class="menu_bar"></div>
<div id="left_bar" class="menu_bar"></div>
<div id="right_bar" class="menu_bar"></div>
<div id="bottom_bar" class="menu_bar"></div>
</div>
</body>
</html>
Glam集团srl
我还是不明白这个问题
编辑2
这只发生在Firefox的firebug控制台中。Chrome控制台没有这个问题。jQuery Lint抛出了错误。它希望您使用
this.id
而不是$(this.attr('id')
,因为this
已经表示具有id
属性的
从jQuery Lint源:
langs = {
en: {
incorrectCall: '%0(%1) called incorrectly',
specialCheckFailed: '%0(%1) special check failed',
...
notBestMethod: 'Insted of accessing the property via %0(%1), use %2 insted',
...
对我有用。请给我们更多的上下文。我们需要查看关联的html…“特殊检查失败”?什么是“特殊检查”?如果您只需要id,请尝试this.id或this.getAttribute('id'),无需使用attr。这不是来自jQuery本身的消息,而是来自jQuery Lint的消息:
// check for non-ideal property/attribute access ( e.g. attr('id') - element.id is faster)
each({'attr': {'id': 'elem.id', 'value': 'jQuery.val()'}}, function(method, attributes) {
addCheck(method, 3, function() {
if (typeof arguments !== 'undefined' && typeof attributes === 'object') {
var match = false;
for (m in arguments) {
if (attributes.hasOwnProperty(arguments[m])) {
match = arguments[m];
}
}
if (match !== false) {
var args = [].splice.call(arguments,0);
return lint.langs[lint.lang].notBestMethod.replace(/%0/, method)
.replace(/%1/, args.join(', '))
.replace(/%2/, attributes.match);
}
}
});
});