У меня есть около 20 переключателей, которые отправляют запрос ajax, который обновляет поле в таблице. Я продублировал, где класс подключается к селектору, потому что мне нужно указать, какие переключатели включены или выключены. Тем не менее, первая кнопка, которую я нажимаю, работает, но после этого мне иногда нужно нажать один раз для некоторых других кнопок, в то время как для остальных требуется два нажатия. Вот код!
прикрепление класса:
$(document).ready(function() {
var user = $(".profile").attr('id');
$('#status').hide();
$('.switch1').checkbox("on",
function(theId) {
$.post("setPerms.php", { user_id: user, val: "1", field: theId }, function(data){
$("#status").text(data).fadeIn(1000);
$('#status').fadeOut(1000);
});
},
function(theId) {
$.post("setPerms.php", { user_id: user, val: "0", field: theId }, function(data){
$("#status").text(data).fadeIn(1000);
$('#status').fadeOut(1000);
});
});
$('.switch0').checkbox("off",
function(theId) {
$.post("setPerms.php", { user_id: user, val: "1", field: theId }, function(data){
$("#status").text(data).fadeIn(1000);
$('#status').fadeOut(1000);
});
},
function(theId) {
$.post("setPerms.php", { user_id: user, val: "0", field: theId }, function(data){
$("#status").text(data).fadeIn(1000);
$('#status').fadeOut(1000);
});
});
});
и вот где функция щелчка: (отдельные файлы)
// click handling
jQuery(this).click(function() {
var theId = $(this).attr('id');
if(state == 'on') {
jQuery(this).find('.iphone_switch').animate({backgroundPosition: -53}, "normal", function() {
jQuery(this).attr('src', settings.switch_off_container_path);
switched_off_callback(theId);
});
state = 'off';
}
else {
jQuery(this).find('.iphone_switch').animate({backgroundPosition: 0}, "normal", function() {
switched_on_callback(theId);
});
jQuery(this).find('.iphone_switch').attr('src', settings.switch_on_container_path);
state = 'on';
}
});
дайте мне знать, если вам нужна дополнительная информация. любая помощь с благодарностью !!