为什么 Firefox 不显示正确的默认选择选项? [英] Why doesn't Firefox show the correct default select option?
问题描述
我正在制作一个网络应用来管理产品 SKUS.其中一部分是将 SKU 与产品名称相关联.在表格的每一行,我都会列出一个 SKU 并显示一个带有产品名称的 框.当前与数据库中该 SKU 相关联的产品被赋予一个类似
selected=selected"
的属性.这可以通过 AJAX 更改和更新.
I'm making a web app to manage product SKUS. One part of that is to associate SKUs with product names. On each row of a table, I list a SKU and display a <select>
box with product names. The product that's currently associated with that SKU in the database is given an attribute like selected="selected"
. This can be changed and updated via AJAX.
有 lot 产品 s - 准确地说是 103 - 这个列表在
There are a lot of product <option>
s - 103 to be exact - and this list is repeated in the <select>
on each row.
从页面上的另一个输入,我使用 jQuery AJAX 请求来添加新的 SKU/产品关联,并清楚地表明它们是立即添加的,我将它们插入到顶部带有一点高光效果的表.随着 SKU 的数量增加超过 10 个左右,如果我刷新页面(从按产品名称排序的数据库中加载所有内容),Firefox 开始显示一些默认选择的错误选项.它显示哪个不正确的选项并不一致,但它似乎混淆了页面重新加载之前存在的选项.
From another input on the page, I am using jQuery AJAX requests to add new SKU/product associations, and to make it clear that they're added instantly, I insert them into the top of the table with a little highlight effect. As the number of SKUs increases past 10 or so, if I refresh the page (which loads everything back out of the database ordered by product name), Firefox starts to show some wrong options as selected by default. It is not consistent about which incorrect option it shows, but it seems to be mixing up the options that existed before the page reload.
如果我使用 Firebug 检查 ,
select=selected"
位于正确的 标签.刷新页面(或离开并重新输入此页面的 URL 以返回)不会使其正确显示,但硬刷新 (Ctrl+F5) 可以.
If I inspect the <select>
using Firebug, the select="selected"
is on the correct <option>
tag. Refreshing the page (or leaving and typing this page's URL back in to return) does not make it show up correctly, but hard refreshing (Ctrl+F5) does.
Chrome 和 IE7 一开始都能正确显示.
Both Chrome and IE7 display this correctly in the first place.
我的理论是,这是 Firefox 缓存策略错误的结果.听起来对吗?有什么办法可以在我的代码中说如果刷新此页面,请使其硬刷新 - 从头开始重新加载所有内容?"
My theory is that this is a result of a faulty cache strategy by Firefox. Does that sound right? Is there any way I can say in my code "if this page is refreshed, make it a hard refresh - reload everything from scratch?"
为了解决这个问题,我改变了策略.
To solve this problem, I changed strategies.
- 以前,我在每个表格行上放了一个
和一长串
,当前值设置为默认值莉>
- 现在,我将当前值放在
中.如果用户点击改变"按钮,我将
替换为
,并将change"替换为
按钮变成确认"按钮.如果他们更改选项并单击确认,AJAX 会更新数据库,
将恢复为
,这次使用新值.
- Previously, I put a
<select>
with a long list of<option>
s on each table row, with the current value set as default - Now, I put the current value in a
<span>
. If the user clicks a "change" button, I replace the<span>
with a<select>
, and the "change" button becomes a "confirm" button. If they change options and click confirm, AJAX updates the database, the and the<select>
goes back to being a<span>
, this time with the new value.
这有两个好处:
- 它修复了上述错误
- 它需要远页面上更少的DOM元素(所有那些多余的
s)
- It fixes the bug described above
- It requires far fewer DOM elements on the page (all those redundant
<option>
s)
推荐答案
Firefox 会在您刷新时保留您选择的表单元素.这是故意的.Ctrl+F5 是硬"刷新,可禁用此行为.
Firefox preserves your selected form elements when you refresh. It's intentional. Ctrl+F5 is a "hard" refresh, which disables this behavior.
--
如果你使用的是 Mac,或者 Command+Shift+R
Or Command+Shift+R if you are on a Mac
这篇关于为什么 Firefox 不显示正确的默认选择选项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!