开发者

How to forbid the browser from caching the status of a radio input?

开发者 https://www.devze.com 2023-01-30 13:07 出处:网络
I have listeners on the event of radio being checked, which works perfect for the first time. But if I refresh the page,the radio input is checked because of browser开发者_JAVA技巧 cache,and the even

I have listeners on the event of radio being checked, which works perfect for the first time.

But if I refresh the page,the radio input is checked because of browser开发者_JAVA技巧 cache,and the event is not fired at all.

How to avoid this trouble?


I've run into this a lot, especially with Firefox. I'm not sure its necessarily valid but i read somewhere recently that adding autocomplete="off" to your form tag will prevent any form element value caching.

There is a post here that provides a JavaScript solution that looks like this:

 setTimeout(
     function(){
         document.getElementById( "form" ).reset();
     },
     5
 );  

EDIT

As your radio's arent in a form this should work:

<input type="radio" name="foo" value="bar" autocomplete="off">Bar
<input type="radio" name="foo" value="baz" autocomplete="off">Baz


You could propably unselect everything using javascript when the beforeunload event fires.

0

精彩评论

暂无评论...
验证码 换一张
取 消