我需要帮助的人我有代码什么可以通过ID清空单输入的值我有2输入让我们说开始时间和结束时间当我点击全天它应该是空的开始时间和结束时间当我检查这个按钮...... 这是我的代码......
<Input type="text" id="startime" />
<input type="text" id="endtime" />
<input type="check" id="remove" />
<script type="text/javascript">
var imgInput = document.getElementById('startime'),
remove = document.getElementById('remove'),
val = imgInput.value;
remove.onchange = function() {
if (this.checked) {
imgInput.value = "";
} else {
imgInput.value = val;
}
}
</script>
帮助赞赏...
答案 0 :(得分:0)
对于复选框,您不应使用onchange事件处理程序,onclick将执行您所需的操作:
remove.onclick = function() {
if (this.checked) {
imgInput.value = "";
} else {
imgInput.value = val;
}
}
然而,如果它被清除,您可能会尝试保存该值,以便可以重新填充,如果是这种情况,那么您还需要在清除文本框之前更新val:
remove.onclick = function() {
if (this.checked) {
val = imgInput.value;
imgInput.value = "";
} else {
imgInput.value = val;
}
}