// 糟糕
h = $('#element').height();
$('#element').css('height',h-20);
建议
$element = $('#element');
h = $element.height();
$element.css('height',h-20);
建议
var $element = $('#element');
var h =
糟糕
var first = $('#first'var second = $('#second'var value = $first.val();
建议 - 在jQuery对象前加$前缀
var $first = $('#first'var $second = $('#second'),var value = $first.val();
var
$first = $('#first'= $first.val(),k = 3,cookiestring = 'SOMECOOKIESPLEASE'
$first.click(function(){
$first.css('border','1px solid red');
$first.css('color','blue');
});
$first.hover();
})
建议
$first.on('click',);
})
$first.on('hover',1)">);
})
);
});
$first.on('click',1)">(){
$first.css({
'border':'1px solid red'
});
});
$second.html(value);
$second.on('click',1)">(){
alert('hello everybody');
});
$second.fadeIn('slow');
$second.animate({height:'120px'},500);
}).fadeIn('slow').animate({height:'120px'},500);
$second.html(value);
$second.on('click',1)">
$second.html(value);
$second
.on('click',1)">function(){ alert('hello everybody');})
.fadeIn('slow')
.animate({height:'120px'},500);
initVar($myVar) {
if(!$myVar) {
$myVar = $('#selector');
}
}
initVar($myVar) {
$myVar = $myVar || $('#selector');
}
if(collection.length > 0){..}
if(collection.length){..}
$container = $("#container"null;
$element = $containerLi.first();
... 许多复杂的操作
better
$containerLi.first().detach();
... 许多复杂的操作
$container.append($element);
$('#id').data(key,value);
建议 (高效)
$.data('#id',key,value);
$container = $('#container'= $('#container li span' 建议 (高效)
$container = $('#container '= $containerLi.find('span');
$('.container > *'
$('.container').children();
$('.someclass :radio'
$('.someclass input:radio');
$('div#myid');
$('div#footer a.myLink' 建议
$('#myid');
$('#footer .myLink');
$('#outer #inner'
$('#inner');
糟糕 - live 已经废弃
$('#stuff').live('click',1)">() {
console.log('hooray' 建议
$('#stuff').on('click',1)">);
});
注:此处可能不当,应为live能实现实时绑定,delegate或许更合适