Вход

Просмотр полной версии : Не работает без обновления страницы


levi4
25.01.2011, 15:44
Есть 2 базы : внутрення и внешняя.
Нужно чтобы при нажатии на ссылку из внутренней добавлялось во внешнюю, при этом чтобы ссылка менялась на удаление из внешней. И наоборот.

Пробовал и кликом и тогглом) но, в любом случае, второй клик работает только если обновить страницу.

$("a[href='#share']").toggle(function(){
var idGlobal = $(this).attr("id");
var span = $(this).parent();
$.post("share.php", {idGlobal:idGlobal},function(data){
var qw = data;
var newA = '<a id="' + idGlobal +'" href="#unshare" alt="' + qw +'" ><img title="dell from base" src="images/eye1.png" /> </a>';
span.html(newA);
});
return false;
},
function(){
var sharedId = $(this).attr("alt");
var thisId = $(this).attr("id");
$.post("unshare.php", {sharedId:sharedId , thisId:thisId});
var newA = '<a id="' + thisId +'" href="#share" target="_blank" ><img title="add to base" src="images/eye.png" /> </a>';
$(this).parent().html(newA);
return false;
});


еще есть toggle наоборот

micscr
25.01.2011, 16:03
а ты вот новый элемент добавил в html, добавь ему и обработку(назначь ему .toggle).

Или узнай, что такое live.

levi4
25.01.2011, 16:11
toggle то есть.

$("a[href='#unshare']").toggle(function(){

var sharedId = $(this).attr("alt");
var thisId = $(this).attr("id");
$.post("unshare.php", {sharedId:sharedId , thisId:thisId});
var newA = '<a id="' + thisId +'" href="#share" target="_blank" ><img title="add to base" src="images/eye.png" /> </a>';
$(this).parent().html(newA);
return false;
},
function(){
var idGlobal = $(this).attr("id");
var span = $(this).parent();
$.post("share.php", {idGlobal:idGlobal},function(data){
var qw = data;
var newA = '<a id="' + idGlobal +'" href="#unshare" alt="' + qw +'" ><img title="dell from base" src="images/eye1.png" /> </a>';
span.html(newA);
});
return false;
});

Не помогает)) и пробовал делать 2 клика .click. Не работает всё равно))
пошёл узнавать про live

levi4
25.01.2011, 16:40
live помог) спасиб

levi4
26.01.2011, 15:12
Теперь работает,но только в firefox ))

$("a[href='#unshare']").live("click",function(){
var sharedId = $(this).attr("alt");
var thisId = $(this).attr("id");
$.post("unshare.php", {sharedId:sharedId , thisId:thisId});
var newA = '<a id="' + thisId +'" href="#share" ><img title="add to base" src="images/eye.png" /> </a>';
$(this).parent().html(newA);
return false;
});


$("a[href='#share']").live("click",function(){
var idGlobal = $(this).attr("id");
var span = $(this).parent();
$.post("share.php", {idGlobal:idGlobal},function(data){
var qw = data;
var regV = /\d+/;
qw = qw.match(regV);
var newA = '<a id="' + idGlobal +'" href="#unshare" alt="' + qw +'" ><img title="dell from base" src="images/eye1.png" /> </a>';
span.html(newA);
});
return false;
});