in my main js file where I put all my jQuery stuff I have following new funcitons:
function getDate(){
var currentTime = new Date();
var month = currentTime.getMonth() + 1;
var day = currentTime.getDate();
var year = currentTime.getFullYear();
return day"."+month+"."+year;
}
function getTime(){
var currentTime = new Date();
var hours = currentTime.getHours();
var minutes = c开发者_运维技巧urrentTime.getMinutes();
if (minutes < 10){
minutes = "0" + minutes;
}
return hours":"+minutes;
}
...but when I have these functions added to my main js file the jquery part does not work anymore. any ideas?
Well for starters, you were concatenating strings wrongly.
function getDate(){
var currentTime = new Date();
var month = currentTime.getMonth() + 1;
var day = currentTime.getDate();
var year = currentTime.getFullYear();
return day + "." + month + "." + year;
}
function getTime(){
var currentTime = new Date();
var hours = currentTime.getHours();
var minutes = currentTime.getMinutes();
if (minutes < 10){
minutes = "0" + minutes;
}
return hours + ":" + minutes;
}
Missing a +
:
return day"."+month+"."+year;
Here as well:
return hours":"+minutes;
Syntax errors will prevent the entire file from being executed. You should really look at your browser's error console before posting.
It probably breaks it because of a syntax error in your functions:
You are missing the '+' in both your returns after 'day' and 'hours'.
return day"."+month+"."+year;
should be
return day+"."+month+"."+year;
and
return hours":"+minutes;
should be
return hours+":"+minutes;
精彩评论