且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

jQuery UI MultiSelect Widget选择保留在IE中,但未保留在Chrome中

更新时间:2022-10-16 23:08:16

调用multiselect插件的unchekAll()方法似乎是最简单的方法.由于我看不到您的代码,也许您没有以正确的方式调用它:

$("select").multiselect("uncheckAll");

但是现在,该方法在哪里调用?

为了实现跨浏览器的一致性,我认为正确的方法是使用onbeforeunload处理程序,据我所知,该处理程序将在所有浏览器中触发.因此,此代码段在所有情况下均适用:

window.onbeforeunload = function(){$("select").multiselect("uncheckAll")};

让我知道这是否可以解决您的问题吗?

I'm using the jQuery MultiSelect Widget. When using IE, if I select 3 options from the basic dropdown, browse to another page and then press the browser back button, the values are retained in the dropdown. If I refresh the page, the values are still retained. A force refresh clears the values.

In Chrome if I do the same thing the values are not retained.

With my website (which is unfortunately not yet accessible via the Internet), in IE8, the checked state of the checkboxes seems to be retained visually but the state of the checkbox is unchecked.

I have tried calling the 'uncheckAll' method and the checkboxes are still checked. I put an alert in my code to display the number of selected options and the value is zero even though checkboxes are selected.

How is the state of the multiselect list being retained by IE and can it be prevented?

Calling unchekAll() method of multiselect plugin seems to be the easiest way. As i cannot see your code, maybe you are not calling it the right way:

$("select").multiselect("uncheckAll");

But now, where to call this method?

For cross browser consistency, i think the right way is to use the onbeforeunload handler, which is fired in all browsers as i'm aware of. So, this snippet should work in all case:

window.onbeforeunload = function(){$("select").multiselect("uncheckAll")};

Let me know if this fix your issue?