开发者

sIFR and jQuery: dynamically replacing text

开发者 https://www.devze.com 2022-12-19 12:11 出处:网络
I have a problem. I would like to update a counter (seen by the user as it\'s displayed in a certain div) when a button is pressed. So this happens when the button is pr开发者_StackOverflow中文版essed

I have a problem. I would like to update a counter (seen by the user as it's displayed in a certain div) when a button is pressed. So this happens when the button is pr开发者_StackOverflow中文版essed:

$("#photo-counter span").empty().append((start_index+1)+"-"+(end_index+1)+" / "+files.length);  
sIFR.replace(netto, { selector: "#photo-counter span"});

As on the first time this runs automatically and everything works fine, but when I click the button the div is not replaced by sIFR.

Can anybody help?


You can actually do this:

sIFR.replacements["#photo-counter span"][0].replaceText((start_index+1)+"-"+(end_index+1)+" / "+files.length);

No need to update the HTML, sIFR takes care of all that for you.


More code could be usefull for solving this.

Anyway, here is a shot:

Change your click to a live click:

$('#yourElement').live('click', function(){
    $("#photo-counter span").empty().append((start_index+1)+"-"+(end_index+1)+" / "+files.length);  
    sIFR.replace(netto,{
        selector: "#photo-counter span"
    });
});

Hope this helps!


here is the full code:

$("#arrow-left").mouseup(function() {
if(!$("#frame > *").is(":animated") && status != "fullscreen"){
$(this).css({"opacity":"1.0"});

arrowClick("left");
}};

function arrowClick(direction) {
(...) /* i dont think the problem is located somewhere here */
refreshCounter(start, end);
(...)
}

function refreshCounter(start_index, end_index) {
if(files.length > 0) {
start_i = start_index;
end_i = end_index;
if(start_index !=null && end_index != null) {
$("#photo-counter span").empty().append((start_index+1)+"-"+(end_index+1)+" / "+files.length);  
sIFR.replace(netto, { selector: "#photo-counter span"});
}
}
0

精彩评论

暂无评论...
验证码 换一张
取 消