gpt4 book ai didi

javascript - 如何在表单输入中使用onload?

转载 作者:行者123 更新时间:2023-12-02 14:54:11 26 4
gpt4 key购买 nike

我有一个功能:

function loadDefaultDate(){

var currentDate = new Date();
var curYear, curMonth, curDay;

curYear = currentDate.getFullYear();
curMonth = ("0" + (currentDate.getMonth() + 1)).slice(-2);
curDay = ("0" + currentDate.getDate()).slice(-2);

document.getElementById("startDate").value = curYear + "-" + curMonth + "-" + curDay;


}

和html表单输入:

<input type=text name="startDate" size=10 maxlength=10 onload="loadDefaultDate()" onclick="javascript:resetValues();">

为什么我在页面加载时没有获得默认日期?

最佳答案

Try with this:

function load() {
console.log("load event detected!");
}
window.onload = load;

关于javascript - 如何在表单输入中使用onload?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35950240/

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