Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
511 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 Reply

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...