这是我的html结构。如果看我的代码,您可以在divChkBoxTimePicker
内看到我们只是做一些JS来汇总时间。在测试时,它会在此div中复制我的整个内容页面。为什么?我可以找到一种方法来擦除此重复的部分。
我只是将我所有的html代码插入$ Body var中,并在php文件的末尾回显此代码。
这是我的代码:
$Body .=
'<div ID="divChkBoxTimePicker">';
$rep = $bdd->query('Select NomGammeOperatoire,IDGammeOperatoire from GammeOperatoire');
foreach ($rep as $GamOperatoire) {
$Body = $Body . "<input type='checkbox' class=\"form-control\" id='chkboxTimePicker" . $GamOperatoire['IDGammeOperatoire'] .
"'><input type='hidden' id='hiddenChkboxTimePicker"
. $GamOperatoire['IDGammeOperatoire'] . "'><label>" . $GamOperatoire['NomGammeOperatoire'] . "</label><br>";
}
$Body = $Body .
'</div>' .
'<script>';
$rep = $bdd->query('Select IDGammeOperatoire from GammeOperatoire');
foreach ($rep as $GamOperatoire) {
$Body = $Body . "$(function(){" .
"$('#hiddenChkboxTimePicker" . $GamOperatoire['IDGammeOperatoire'] . "').timepicker();" . //Defini le timepicker
"$('#hiddenChkboxTimePicker" . $GamOperatoire['IDGammeOperatoire'] . "').on('change', function(){" .
"var SOMME='00:00';";
$rep = $bdd->query('Select count(*) as NB from GammeOperatoire');
$Nb = $rep->fetch();
$Nb = $Nb['NB'];
$Body = $Body . "for(var i=1;i<=" . $Nb . ";i++){" .
"if(document.getElementById('chkboxTimePicker'+i).checked){" .
"SOMME=addTimes(SOMME,document.getElementById('hiddenChkboxTimePicker'+i).value);}}" .
"document.getElementById('DureeTot').innerHTML=SOMME;});" . //Met a jour la valeur de la duree Tot
"document.getElementById('hiddenChkboxTimePicker" . $GamOperatoire['IDGammeOperatoire'] . "').value='00:00';});" .//Remise a zero après ajout de la duree à la duree Tot
"document.getElementById('chkboxTimePicker" . $GamOperatoire['IDGammeOperatoire'] . "').onclick = function(){" .
"if(document.getElementById('chkboxTimePicker" . $GamOperatoire['IDGammeOperatoire'] . "').checked){" .
"$('#hiddenChkboxTimePicker" . $GamOperatoire['IDGammeOperatoire'] . "').timepicker('show');}" .//affiche le timepicker
"else" .
"{" .
"DureeTot=document.getElementById('DureeTot').innerHTML;" .
"DureeTot=removeTimes(DureeTot,document.getElementById('hiddenChkboxTimePicker" . $GamOperatoire['IDGammeOperatoire'] . "').value);" .
"document.getElementById('DureeTot').innerHTML=DureeTot;" .
"document.getElementById('hiddenChkboxTimePicker" . $GamOperatoire['IDGammeOperatoire'] . "').value='00:00';" .
"}" .
"};" .
";";
};
$Body = $Body .
"</script>";
答案 0 :(得分:0)
看起来AddTimes函数没有返回值,而是返回了对容器对象的引用?如果不了解addTimes函数的作用,就无法判断。
您还要将jQuery代码与非jQuery getElementById混合使用,应避免使用。整个使用jQuery。 我还要建议的是从您的php代码中删除javascript,而只是在php中生成一个ID数组,然后在单个javascript调用中将其传递给该函数。