【发布时间】:2020-12-15 21:09:19
【问题描述】:
我有一个<select> <option></option </select> 来代表中断报告的开始和结束日期,分别称为中断开始数据和中断结束日期。此外,我有一个文本字段来输入名为 Amount 的中断报告的数值。
注意:选项是由 Perl 脚本创建的。
对于文本字段以及开始和结束日期字段,我有一个单独的 reset 和 clear 锚标记。当单击 reset 作为开始或结束日期时,它会将当前日期设置为相应的字段(开始或结束),对于金额字段,它将设置为值 150。当点击clear时会清除相应的字段。
现在我的问题是 Amount 字段的 rest 和 clear 工作正常。对于开始日期和结束日期,指针都指向选项中的所需索引(说清楚它指向空选项并重置其指向当前日期、月份、年份),但这并没有反映在我的网页中无需重新加载页面(但这也不适用于 chrome)。
我想让它像金额字段一样工作。
/*
Start Date snippet is the same for month and year
*/
<lable>Outage Start Date</lable>
<select>
for(sort keys $startDateSet) {
if($_ eq lstStartDate) {
$sel = "selected";
}
else {
$sel = "";
}
print "<option". $sel. "value=".$startDateSet[$_]."</option>
}
</select>
<a id="lstStartDate" href="javascript:clearOutageStartDate();">clear</a>
<a id="lstStartDate" href="javascript:restOutageStartDate();">reset</a>
/*
Same for the end date
*/
function clearOutageStartDate() {
document.outage_report.lstStartDate.selectedIndex = -1;
document.outage_report.lstStartMonth.selectedIndex = -1;
document.outage_report.lstStartYear.selectedIndex = -1;
}
/*
Same for the end date
*/
function resetOutageStartDate(month, date, year) {
document.outage_report.lstStartDate.value = date;
document.outage_report.lstStartMonth.value = month;
document.outage_report.lstStartYear.value = year;
}
【问题讨论】:
-
欢迎来到 SO。请提供足够的 html 以根据 minimal reproducible example 重现您的问题
-
你的锚标签在按钮内吗?我们可以看看你的 HTML 代码吗?
-
它是一个 .cgi 文件。我添加了 perl 代码 sn-p,它为开始日期创建选项,月份和年份相同
-
会有什么问题??同样适用于文本字段
标签: javascript html dom layout