I'm just a beginner, but can someone help me out?
(我只是一个初学者,但是有人可以帮我吗?)
I have an HTML page with a couple of input fields, and I want the fields to be cleared when the page is refreshed.
(我有一个包含两个输入字段的HTML页面,并且希望刷新页面时清除这些字段。)
My HTML looks like this:
(我的HTML看起来像这样:)
<input type='text' id='input_field' value=''>
Then, toward the beginning of my script, there's this:
(然后,在我的脚本开始处,有以下内容:)
document.getElementById('input_field').value = '';
This works fine in Firefox;
(在Firefox中工作正常;)
when the page is refreshed, the value is emptied and the field is cleared.(刷新页面时,将清空该值并清除该字段。)
It does not work in Microsoft Edge;
(它在Microsoft Edge中不起作用。)
when the page is refreshed, the actual value is emptied, but the contents of the field remain.(刷新页面时,将清空实际值,但该字段的内容仍保留。)
I've also tried wrapping my input element(s) in a form element, and using JavaScript to reset the form, but the results are the same.
(我也尝试过将输入元素包装在一个form元素中,并使用JavaScript重置该表单,但是结果是相同的。)
As you can see, I've kept the value attribute in the HTML, but only for purposes of demonstration and experimentation.
(如您所见,我将value属性保留在HTML中,但仅用于演示和实验目的。)
Omitting it has no effect in either browser.(忽略它在任一浏览器中均无效。)
However, if I leave the HTML attribute but omit the JavaScript statement, both browsers behave differently: in Edge, the contents of the field "catch up" to the actual value (ie, the field clears), but only after the page is refreshed twice;(但是,如果我保留HTML属性而忽略JavaScript语句,则两种浏览器的行为都不同:在Edge中,仅在刷新页面后,字段的内容才会“赶上”到实际值(即,该字段将清除)。两次;)
and in Firefox, this fails to update the value at all, no matter how many times the page is refreshed.(在Firefox中,无论刷新页面多少次,这都根本无法更新值。)
Finally, if I edit the source in any way and then reload the page in Edge, it empties the actual value and also clears the field, but only on that initial reload.
(最后,如果我以任何方式编辑源代码,然后在Edge中重新加载页面,它将清空实际值,并清除该字段,但仅限于该初始重新加载。)
After that, the problem persists.(之后,问题仍然存在。)
This makes me wonder if it's a cache issue.(这使我想知道这是否是缓存问题。)
Any help or suggestions?
(有什么帮助或建议吗?)
ask by TeRrIrAoLr translate from so