FireFox 下selected = 'selected' 失效的解決方案

來源:互聯網
上載者:User

使用javascript動態改變select的selected屬性時,發現不起作用。

某個<option selected = 'selected' >hello</option>明明有selected = 'selected' 但是選中的卻不是它

只有預先寫好的<option selected = 'selected' >hello</option>才會顯示被選中。

這個問題在firefox5下才會出現,在FF4下不會,所以我猜想是不是FF5的一個BUG。

可能的原因是FF5處於效能考慮,將一開始載入的dom元素的一些屬性緩衝起來了,而當使用F5重新整理的時候,FF依然使用緩衝中的屬性,而不使用新的屬性。

只有使用CTRL+F5強制重新整理時,才能渲染新的屬性。

最終,在stackoverflow中找到瞭解決方法:http://stackoverflow.com/questions/6849057/firefox-5-not-using-select-selected-value-on-page-refresh-retaining-old-value

裡面說只要在select標籤中加autocomplete = ‘off “就行了,<select id="sportid" name="sportid" autocomplete="off">

試了一下,確實有用。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.