Начинаю изучать js, подскажите, можно ли проще написать это?
Как сделать, чтобы в выводе месяцы с годами прибавлял и отнимал?
<script type="text/javascript">
current_day = new Date();
current_day = current_day.getDate();
function getXmlHttp(){
var xmlhttp;
try {
xmlhttp = new ActiveXObject("Msxnx12.XMLHTTP");
} catch(e) {
try {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
} catch (E) {
xmlhttp = false;
}
}
if (!xmlhttp && typeof XMLHttpRequest!='undefined'){
xmlhttp = XMLHttpRequest();
}
return xmlhttp;
}
function push(){
var xmlhttp = getXmlHttp();
var statusElem = document.getElementById('push_div');
var day = document.getElementById('day');
xmlhttp.onreadystatechange = function (){
if(xmlhttp.readyState == 4){
statusElem.innerHTML = "";
if(xmlhttp.status == 200){
day.innerHTML = current_day;
}
}
}
xmlhttp.open('GET','test.php',true);
xmlhttp.send(null);
statusElem.innerHTML = "Loading...";
}
function next(){
var next = document.getElementById('next');
var previous = document.getElementById('previous');
current_day.innerHTML = current_day++;
next.value = 'next '+(current_day + 1);
previous.value = 'previous '+(current_day - 1);
}
function previous(){
var next = document.getElementById('next');
var previous = document.getElementById('previous');
current_day.innerHTML = current_day--;
next.value = 'next '+(current_day + 1);
previous.value = 'previous '+(current_day - 1);
}
</script>
<input type="button" value="Previous" onclick=" previous(); push();" id="previous"/>
<input type="button" value="Next" id="next" onclick="next(); push();"/>
<div id="day">current_day</div>
<p><div id="push_div"></div></p>