Ai đó có thể cho tôi biết lý do tại sao setTimeout được sử dụng trong mã bên dưới không hoạt động? Nó chỉ chạy hàm ngay lập tức.SetTimeout không trì hoãn cuộc gọi hàm
function change_txt_font(elem, id, text_fnt){
current_width = parseInt($('#span_text'+id).css('width'));
current_height = parseInt($('#span_text'+id).css('height'));
current_font_size = parseInt($("#span_text"+id).css("font-size"));
parent.document.getElementById(elem+'_f').value=text_fnt;
$('#span_text'+id).css('font-family',text_fnt);
$('#'+elem).css('font-family',text_fnt);
setTimeout(adjust_for_font(id),2000);
}
function adjust_for_font(id){
alert("function")
alert("id = "+id)
new_height = parseInt($('#span_text'+id).css('height'));
new_width = parseInt($('#span_text'+id).css('width'));
width_ratio = parseFloat(current_width/new_width)
height_ratio = parseFloat(current_height/new_height)
new_font_size = current_font_size * Math.min(width_ratio,height_ratio)
$("#text"+id).css("font-size", (parseFloat(new_font_size) - 1) + "px");
$("#span_text"+id).css("font-size", (parseFloat(new_font_size) - 1) + "px");
document.getElementById("form_front_text"+id).submit();
}document.getElementById("form_front_text"+id).submit();
}
Mọi trợ giúp đều được đánh giá cao.
'setTimeout (function() {adjust_for_font (id);}, 2000)' – Sim
Cảm ơn Sim của bạn một ngôi sao! Tôi vẫn quen với javascript - và nó hiển thị vào những lúc! Cảm ơn một lần nữa. –