如果DIV(计时器)自行关闭,我想清除表格。
function openForm() {
document.getElementById("myForm").style.display = "block";
startTimer();
}
var timer;
function startTimer() {
timer = setTimeout(hideDiv, 60000);
}
document.addEventListener("keydown", stopTimer, false);
function hideDiv() {
document.getElementById('myForm').reset();
//$("#client")[0].reset();
document.getElementById('myForm').style.display = 'none';
}
function showDiv() {
document.getElementById('myForm').style.display = 'block';
}
function stopTimer() {
clearTimeout(timer);
startTimer();
showDiv();
}
startTimer();
HTML:
<div class="form-popup" id="myForm">
<form name="form" class="form-container" method="post" onsubmit="return doValidate()">
<h1 align="center">Reservierung erstellen</h1>
<label><b>Organisator:</b><br> <input placeholder="Name (Max Mustermann)" id="name" list="users" name="mitarbeiter" required /></label>
<datalist id="users" class="dle" > <!-- autocomplete="off" -->
<?php
for ($i=0; $i<$counts; $i++) {
echo '<option value="'.$AllData[$i]["mail"][0].'">'.$AllData[$i]["cn"][0].'</option>';
}
?>
</datalist>
<label for="psw"><br><br><b>Zeit der Reservierung:</b></label><br>
von <input type="time" name="zeitstart"> Uhr bis <input type="time" name="zeitende"> Uhr <br><br>
<!-- <input type="submit" class="btn" name="submit" value="Reservierung erstellen" /> -->
<button type="submit" class="btn" name="submit">Reservierung erstellen</button>
<button type="reset" class="btn cancel" onclick="hideDiv()">Abbrechen</button>
</form>
</div>
命令应该在“ hideDiv()”中正确吗? 我用“ document.getElementById('myForm')。reset();”尝试过但这没用。
感谢您的帮助。
答案 0 :(得分:0)
也许尝试获取表单的子输入元素并将其值设置为''。
var inputs = document.getElementById("myForm").getElementsByTagName("input");
for (var i = 0; i < inputs.length; i++) {
inputs[i].value = '';
}