用下面提到的脚本替换您的整个 javascript/Jquery 脚本,并根据您的要求检查更改
$(document).ready(function(){
$('a.sortLink1').on('click',function(event){
event.preventDefault(event);
if ($(this).hasClass('selected')) {
$(this).removeClass('selected');
var SelectedAry = $(".selected");
var flag = false;
if(SelectedAry != undefined && SelectedAry.length == 0)
flag = true
sortResult(flag);
}
else{
$('a.sortLink1').removeClass('selected');
$(this).addClass('selected');
var SelectedAry = $(".selected");
var flag = false;
if(SelectedAry != undefined && SelectedAry.length == 0)
flag = true
sortResult(flag);
}}
);
$('a.sortLink2').on('click',function(event){
event.preventDefault(event);
if ($(this).hasClass('selected')) {
$(this).removeClass('selected');
var SelectedAry = $(".selected");
var flag = false;
if(SelectedAry != undefined && SelectedAry.length == 0)
flag = true
sortResult(flag);
}
else{
$('a.sortLink2').removeClass('selected');
$(this).addClass('selected');
var SelectedAry = $(".selected");
var flag = false;
if(SelectedAry != undefined && SelectedAry.length == 0)
flag = true
sortResult(flag);
}}
);
$('a.sortLink3').on('click',function(event){
event.preventDefault(event);
if ($(this).hasClass('selected')) {
$(this).removeClass('selected');
var SelectedAry = $(".selected");
var flag = false;
if(SelectedAry != undefined && SelectedAry.length == 0)
flag = true
sortResult(flag);
}
else{
$('a.sortLink3').removeClass('selected');
$(this).addClass('selected');
var flag = false;
if(SelectedAry != undefined && SelectedAry.length == 0)
flag = true
sortResult(flag);
}}
);
$('a.sortLink4').on('click',function(event){
event.preventDefault(event);
if ($(this).hasClass('selected')) {
$(this).removeClass('selected');
var SelectedAry = $(".selected");
var flag = false;
if(SelectedAry != undefined && SelectedAry.length == 0)
flag = true
sortResult(flag);
}
else{
$('a.sortLink4').removeClass('selected');
$(this).addClass('selected');
var SelectedAry = $(".selected");
var flag = false;
if(SelectedAry != undefined && SelectedAry.length == 0)
flag = true
sortResult(flag);
}}
);
$('a.sortLink5').on('click',function(event){
event.preventDefault(event);
if ($(this).hasClass('selected')) {
$(this).removeClass('selected');
var SelectedAry = $(".selected");
var flag = false;
if(SelectedAry != undefined && SelectedAry.length == 0)
flag = true
sortResult(flag);
}
else{
$('a.sortLink5').removeClass('selected');
$(this).addClass('selected');
var SelectedAry = $(".selected");
var flag = false;
if(SelectedAry != undefined && SelectedAry.length == 0)
flag = true
sortResult(flag);
}}
);
$('.basket').addClass('showMe');
positionThumbnails();
});
function sortResult (flag){
$('.results .basket').each(function(){
var thumbnailKeywords = $(this).attr('data-keywords');
if(flag){
$(this).addClass('showMe').removeClass('hideMe');
}else{
var mymatch = false;
var SelectedAry = $(".selected");
SelectedAry.each(function(){
var newKeyword = $(this).attr("data-keyword");
var test_regexp = new RegExp("\\b"+newKeyword+"\\b");
mymatch = thumbnailKeywords.match(test_regexp);
if(!mymatch)
return false;
});
if(mymatch){
$(this).addClass('showMe').removeClass('hideMe');
}else{
$(this).addClass('hideMe').removeClass('showMe');
}
}
});
positionThumbnails();
}
function positionThumbnails(){
$('.basket.hideMe').animate({opacity:0},500,function(){
$(this).css({'display':'none'});
});
$('.basket.showMe').each(function(index){
$(this).css('display','block').animate({opacity:1},500)
});
}
请检查您的要求并比较您的脚本。有关 jsfiddle 的知识,请访问“ http://jsfiddle.net/LSMxC/32/ ”。请在您的最后检查。