我的jquery:
$('#imgCancel').toggle(function () {
$.each($("#List li"), function (index, item) {
$('#menuList li').removeClass("Selected");
});
$('#txtName').html('');
$('#imgAdd').show();
$('#imgUpdate').hide();
});
}, function () { //Eroor ---- Expect identifier or string
$('#List li:First').addClass("Selected");
$('#imgAdd').hide();
$('#imgUpdate').show();
});
}
});
但它不是处理切换的正确方法。我得到了错误。如何执行此任务切换plz suggest.Thanks。
答案 0 :(得分:2)
看起来你对})
s:
$('#imgCancel').toggle(//BEGIN TOGGLE
function () {//BEGIN FIRST FUNCTION
//the each was unnecessary since this selector uses an ID, each iteration was just selecting the same thing over and over
$('#menuList li').removeClass("Selected");
$('#txtName').html('');
$('#imgAdd').show();
$('#imgUpdate').hide();
},//END FIRST FUNCTION
function () {//BEGIN SECOND FUNCTION
//notice here I changed "First" to "first", the capital F was most likely causing this line to not work properly
$('#List li:first').addClass("Selected");
$('#imgAdd').hide();
$('#imgUpdate').show();
}//END SECOND FUNCTION
);//END TOGGLE
答案 1 :(得分:0)
$('#imgCancel').toggle(function () {
$.each($("#List li"), function (index, item) {
$('#menuList li').removeClass("Selected");
});
$('#txtName').html('');
$('#imgAdd').show();
$('#imgUpdate').hide();
}, function () {
$('#List li:First').addClass("Selected");
$('#imgAdd').hide();
$('#imgUpdate').show();
});
如果你想逃避第一个
,你可以用它替换它们$.each($("#List li"), function (index, item) {
if(index != 0){
$('this').removeClass("Selected");
}
});
答案 2 :(得分:0)
尝试这一点,希望它能解决您有冗余});
$('#imgCancel').toggle(function () {
$.each($("#List li"), function (index, item) {
$('#menuList li').removeClass("Selected");
});
$('#txtName').html('');
$('#imgAdd').show();
$('#imgUpdate').hide();
}, function () {
$('#List li:First').addClass("Selected");
$('#imgAdd').hide();
$('#imgUpdate').show();
}
);