gpt4 book ai didi

javascript - SetTimeout 不延迟函数调用

转载 作者:可可西里 更新时间:2023-11-01 01:45:09 24 4
gpt4 key购买 nike

<分区>

有人能告诉我为什么下面代码中使用的 setTimeout 不起作用吗?它只是直接运行函数。

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();
}

感谢任何帮助。

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com