admin管理员组文章数量:1399347
This is my Java Script function:-
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;}
}
How can i call this function on page load time on browser? This function should call at the time of Page Load how can i do this? how can a function bind with the page load?
This is my Java Script function:-
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;}
}
How can i call this function on page load time on browser? This function should call at the time of Page Load how can i do this? how can a function bind with the page load?
Share Improve this question asked Feb 23, 2015 at 14:01 Sachin YadavSachin Yadav 1873 gold badges4 silver badges15 bronze badges3 Answers
Reset to default 2You can also use plain JavaScript as follows:
window.onload = function() {
init();
doSomethingElse();
};
You can use ready event in jquery api
$( document ).ready(function() {
ValidatefuneralDate();
});
which is equivalent to:
$(function() {
ValidatefuneralDate();
});
this will get invoked when the DOM is ready.
or you can use pageload event
$(document).on("pageload",function(){
ValidatefuneralDate();
});
The pageload event is triggered after the page has been successfully loaded and inserted into the DOM.
You are using jQuery so just use the standard jQuery page ready method:
$(document).ready(function() {
ValidatefuneralDate();
})
Or using the shorthand syntax:
$(function() {
ValidatefuneralDate();
})
本文标签: model view controllerHow to call a javascript function on pageload in MVCStack Overflow
版权声明:本文标题:model view controller - How to call a javascript function on pageload in MVC - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744193286a2594619.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论