gpt4 book ai didi

javascript - 如何在 MVC 中的页面加载时调用 javascript 函数

转载 作者:行者123 更新时间:2023-11-28 07:35:19 24 4
gpt4 key购买 nike

这是我的 Java 脚本函数:-

    function ValidatefuneralDate() {
var today;
var currentDate = new Date();
var year = currentDate.getFullYear();
var month = currentDate.getMonth() + 1;
var day = currentDate.getDate();

if (window.location.href.indexOf("en-US") > -1) {
today = month + '/' + day + '/' + year;
var selectedDate = $("#Month option:selected").
val() + '/' + $("#Day option:selected").text() +
'/' + $("#Year option:selected").text();
}
else {
today = day + '/' + month + '/' + year;
var selectedDate = $("#Day option:selected").
text() + '/' + $("#Month option:selected").
val() + '/' + $("#Year option:selected").text();
}
if ($("#Month option:selected").val()==2)
{
$("#Day option[value='31']").hide();
$("#Day option[value='30']").hide();
if ($("#Year option:selected").text() == 2016) {
$("#Day option[value='29']").show();
}
else
{
$("#Day option[value='29']").hide();
}
}
else if($("#Month option:selected").
val() == 4 || $("#Month option:selected").
val() == 6 || $("#Month option:selected").
val() == 9 || $("#Month option:selected").val() == 11)
{
$("#Day option[value='29']").show();
$("#Day option[value='30']").show();
$("#Day option[value='31']").hide();
}
else
{
$("#Day option[value='31']").show();
}
if (selectedDate < today) {
$("#lblFeneralDate").
html('@Html.R(VirtualPath,"ValidatefuneralDate")');
return false;
}
else { return true;}
}

如何在浏览器的页面加载时调用此函数?此函数应在页面加载时调用,我该如何执行此操作?函数如何与页面加载绑定(bind)?

最佳答案

您还可以使用纯 JavaScript,如下所示:

window.onload = function() {
init();
doSomethingElse();
};

关于javascript - 如何在 MVC 中的页面加载时调用 javascript 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28675505/

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