我遇到了一個我試圖構建的函數的問題。用於增加或減少日期函數javascript的問題
事實上,我有幾個日期應該改變+ x天或 - x天。
但不是所有的日期都應該改變。因爲我有一些確認的日期。
其實在MySQL中我有date_action和date_validation列。
當data_validation ='0000-00-00'時,表示它沒有被確認。當它等於一個日期時,這意味着它被驗證。
在我的頁面上,我顯示了很多信息。我想改變,如果可能的,沒有經過驗證,但我失去了弗裏我已經構建功能的所有日期:
<script type="text/javascript">
function lz(x){
return x.toString().replace(/^(\d)$/,'0$1')
}
function addday() {
var items = new Array();
var itemCount = document.getElementsByClassName("datepicker hasDatepicker");
items[0] = document.getElementById("date" + (1)).value;
items[1] = document.getElementById("date" + (2)).value;
items[2] = document.getElementById("date" + (3)).value;
items[3] = document.getElementById("date" + (4)).value;
items[4] = document.getElementById("date" + (5)).value;
items[5] = document.getElementById("date" + (6)).value;
items[6] = document.getElementById("date" + (7)).value;
items[7] = document.getElementById("date" + (8)).value;
items[8] = document.getElementById("date" + (9)).value;
items[9] = document.getElementById("date" + (10)).value;
for (var i = 0; i < itemCount.length; i++) {
items[i] = document.getElementById("date" + (i + 1)).value;
var itemDtParts = items[i].split("-");
var itemDt = new Date(parseInt(itemDtParts[2],10), parseInt(itemDtParts[1],10)-1, parseInt(itemDtParts[0],10)+ +nb);
nb=document.getElementById('nb').value;
itemCount[i].value = lz(itemDt.getDate())+"-"+lz(itemDt.getMonth()+1)+"-"+itemDt.getFullYear()
}
return items;
}
</script>
<script type="text/javascript">
function subday() {
var items = new Array();
var itemCount = document.getElementsByClassName("date");
items[0] = document.getElementById("date" + (1)).value;
items[1] = document.getElementById("date" + (2)).value;
items[2] = document.getElementById("date" + (3)).value;
items[3] = document.getElementById("date" + (4)).value;
items[4] = document.getElementById("date" + (5)).value;
items[5] = document.getElementById("date" + (6)).value;
items[6] = document.getElementById("date" + (7)).value;
items[7] = document.getElementById("date" + (8)).value;
items[8] = document.getElementById("date" + (9)).value;
items[9] = document.getElementById("date" + (10)).value;
for (var i = 0; i < itemCount.length; i++) {
items[i] = document.getElementById("date" + (i + 1)).value;
var itemDtParts = items[i].split("-");
var itemDt = new Date(parseInt(itemDtParts[2],10), parseInt(itemDtParts[1],10)-1, parseInt(itemDtParts[0],10)+ -nb);
nb=document.getElementById('nb').value;
itemCount[i].value = lz(itemDt.getDate())+"-"+lz(itemDt.getMonth()+1)+"-"+itemDt.getFullYear()
}
return items;
}
</script>
這裏是的jsfiddle。事實上,它使用類似mysql的查詢來選擇好日期:
<?php $sql2 = "SELECT * FROM agenda WHERE n_doss='".mysql_real_escape_string($_GET['n_doss'])."' AND qualite='".mysql_real_escape_string($_GET['qualite'])."' AND liasse='".$_GET['liasse']."' AND `date_validation`='0000-00-00' ORDER BY `date_action` ASC" ;
$rules2=mysql_query($sql2) ; $i2=0;
while($data2=mysql_fetch_assoc($rules2)) {?>
items[<?php echo $i2 ; ?>] = document.getElementById("date" + (<?php echo ++$i2 ; ?>)).value;
<?php }?>
但它取代了其他不關心這個變化的日期。
這裏是更精確http://jsfiddle.net/pgLpj/