In my program, there are two buttons and in the center of the two buttons there is a space for month to display dynamically using JSP, e.g. << current month >>
. The <<
and >>
are two buttons.
在我的程序中,有两个按钮,并且在两个按钮的*有一个用于动态显示的月份空间,例如: “当月”。 < <和> >是两个按钮。
I need a logical or a programmatic explanation for the following to occur:
我需要对以下内容进行逻辑或程序化解释:
- When I click on the left button the previous month of the current month should display.
- 当我点击左键时,应显示当月的前一个月。
- When I click on the right button the next month of the current month should display.
- 当我点击右键时,应显示当月的下个月。
This should happen dynamically. How can I do that with help of JSP, JS and/or Ajax?
这应该动态发生。如何借助JSP,JS和/或Ajax做到这一点?
1 个解决方案
#1
1
You can easily do that with jQuery:
您可以使用jQuery轻松完成:
HTML:
HTML:
<a id="Previous" href="#"><<</a>
<span id="CurrentMonth">January</span>
<a id="Next" href="#">>></a>
Javascript:
使用Javascript:
var currentMonth = 0;
$(function(){
var months = ["January", "February", "March", "April", "May", "June",
"July", "August", "September", "October", "November", "December"];
$("#Next").click(function() {
if (currentMonth < 11) {
currentMonth++;
$("#CurrentMonth").text(months[currentMonth]);
}
});
$("#Previous").click(function() {
if (currentMonth > 0) {
currentMonth--;
$("#CurrentMonth").text(months[currentMonth]);
}
});
});
If you want to also inform the server about the current month, you need to create an Ajax service (using for example a servlet).
如果您还想要通知服务器当前月份,您需要创建一个Ajax服务(例如使用servlet)。
#1
1
You can easily do that with jQuery:
您可以使用jQuery轻松完成:
HTML:
HTML:
<a id="Previous" href="#"><<</a>
<span id="CurrentMonth">January</span>
<a id="Next" href="#">>></a>
Javascript:
使用Javascript:
var currentMonth = 0;
$(function(){
var months = ["January", "February", "March", "April", "May", "June",
"July", "August", "September", "October", "November", "December"];
$("#Next").click(function() {
if (currentMonth < 11) {
currentMonth++;
$("#CurrentMonth").text(months[currentMonth]);
}
});
$("#Previous").click(function() {
if (currentMonth > 0) {
currentMonth--;
$("#CurrentMonth").text(months[currentMonth]);
}
});
});
If you want to also inform the server about the current month, you need to create an Ajax service (using for example a servlet).
如果您还想要通知服务器当前月份,您需要创建一个Ajax服务(例如使用servlet)。