Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
506 views
in Technique[技术] by (71.8m points)

javascript - 防止Chrome向后/向前填充历史记录中的选择字段(Prevent chrome from filling select field on history backward/forward)

I have a form with custom onsubmit handler which reads the value selected in a <select> input.

(我有一个带有自定义onsubmit处理程序的表单,该表单读取在<select>输入中<select>的值。)

<form onsubmit="handleSubmit()">
  <select id="selector" name="selector">
    <option selected hidden disabled value>Select an option</option>
    <option value="1">1</option>
    <option value="2">2</option>
  </select>
</form>

When I open this page in Chrome, select a value from the dropdown and go one page back in my history, then one page forth to land on the page with the form again, that option is already selected while accessing the field via JS with $('#selector').val() returns me an empty value.

(当我在Chrome中打开此页面时,请从下拉列表中选择一个值,然后再返回历史记录中的一页,然后再次向前翻一页以使用表单进入该页面,该选项已在通过JS通过$('#selector').val()访问字段时被选中$('#selector').val()返回一个空值。)

I already tried specifying autocomplete="off" on the <select> tag without success.

(我已经尝试在<select>标记上指定autocomplete="off" ,但是没有成功。)

Also disabling cache for that page didn't help.

(另外,禁用该页面的缓存也无济于事。)

Any suggestions on how to get this fixed?

(关于如何解决此问题的任何建议?)

  ask by Dero translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...