gpt4 book ai didi

javascript - 加载页面时停止触发 javascript

转载 作者:太空宇宙 更新时间:2023-11-04 16:07:27 25 4
gpt4 key购买 nike

我正在使用 <body onload="dis()"> 在 body 上调用此函数 onload

function dis(){
if($('#stname').val() == ""){
$('#update').hide();
$('#newstore').show();
}
else {
$('#update').show();
$('#newstore').hide();
}
}

基本上我想检查特定输入框是否为空或未加载。如果它是空的,应该显示 newstore 按钮。如果没有,它应该显示更新按钮。但是这样,它在页面加载时按我想要的方式工作,但是当我在 stname 中键入内容时, 按钮切换。有什么方法可以应对?有没有办法在页面加载完成时停止 javascript 触发?

最佳答案

你需要做的是

$(window).on("load",function(){
if($('#stname').val() == ""){
$('#update').hide();
$('#newstore').show();
}
else {
$('#update').show();
$('#newstore').hide();
}
})

关于javascript - 加载页面时停止触发 javascript,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36996919/

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