SIFR و jQuery: استبدال النص ديناميكيًا
سؤال
لدي مشكلة. أرغب في تحديث عداد (ينظر إليه المستخدم كما يتم عرضه في DIV معين) عند الضغط على زر. لذلك يحدث هذا عند الضغط على الزر:
$("#photo-counter span").empty().append((start_index+1)+"-"+(end_index+1)+" / "+files.length);
sIFR.replace(netto, { selector: "#photo-counter span"});
كما هو الحال في أول مرة يتم تشغيل هذا تلقائيًا ويعمل كل شيء بشكل جيد ، ولكن عندما أنقر على الزر div
لم يتم استبداله بـ sIFR
.
هل يمكن لأي شخص أن يساعد؟
المحلول
يمكنك فعل ذلك في الواقع:
sIFR.replacements["#photo-counter span"][0].replaceText((start_index+1)+"-"+(end_index+1)+" / "+files.length);
لا حاجة لتحديث HTML ، SIFR يعتني بكل ذلك لك.
نصائح أخرى
يمكن أن يكون المزيد من التعليمات البرمجية مفيدة لحل هذا.
على أي حال ، هذه لقطة:
قم بتغيير النقر إلى 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"
});
});
أتمنى أن يساعدك هذا!
هنا هو الكود الكامل:
$("#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"});
}
}
لا تنتمي إلى StackOverflow