2. Create a div element where the calendar will be displayed:
HTML:
<div id="calendar"></div>
3. Create a JavaScript function to generate the calendar:
JavaScript:
function generateCalendar(year, month) {
var calendar = '<table>';
var date = new Date(year, month, 1);
var daysInMonth = new Date(year, month + 1, 0).getDate();
var weekdays = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];
// Create header row with weekdays
calendar += '<tr>';
for (var i = 0; i < weekdays.length; i++) {
calendar += '<th>' + weekdays[i] + '</th>';
}
calendar += '</tr>';
// Fill in days of the month
var day = 1;
var dayOfWeek = date.getDay();
calendar += '<tr>';
for (var i = 0; i < 7; i++) {
if (i < dayOfWeek) {
calendar += '<td></td>';
} else if (day <= daysInMonth) {
calendar += '<td>' + day + '</td>';
day++;
} else {
calendar += '<td></td>';
}
}
calendar += '</tr>';
// Add remaining rows of the calendar
while (day <= daysInMonth) {
calendar += '<tr>';
for (var i = 0; i < 7; i++) {
if (day <= daysInMonth) {
calendar += '<td>' + day + '</td>';
day++;
} else {
calendar += '<td></td>';
}
}
calendar += '</tr>';
}
calendar += '</table>';
return calendar;
}
4. Call the function with the desired year and month:
JavaScript:
var calendarHtml = generateCalendar(2021, 8);
$('#calendar').html(calendarHtml);
This will generate a calendar for August 2021 and insert it into the element with id "calendar". You can modify the CSS to style the calendar as desired.
<script src="You do not have permission to view the full content of this post.Log in or register now."></script>
<script>
$(document).ready(function() {
$('#add').click(function() {
var num1 = parseFloat($('#num1').val());
var num2 = parseFloat($('#num2').val());
var result = num1 + num2;
$('#result').val(result);
});
$('#subtract').click(function() {
var num1 = parseFloat($('#num1').val());
var num2 = parseFloat($('#num2').val());
var result = num1 - num2;
$('#result').val(result);
});
$('#multiply').click(function() {
var num1 = parseFloat($('#num1').val());
var num2 = parseFloat($('#num2').val());
var result = num1 * num2;
$('#result').val(result);
});
$('#divide').click(function() {
var num1 = parseFloat($('#num1').val());
var num2 = parseFloat($('#num2').val());
var result = num1 / num2;
$('#result').val(result);
});
});
</script>