Checkbox initialization after refreshing in IE _ form special effects

Source: Internet
Author: User
There is a requirement in the project that requires the checkbox on the page to be re-initialized when the page is refreshed or rolled back, that is, it is in the unselected status and does not save the previous status. In the first day, this function is very simple. In a checkbox, add a script to set the checked attribute of this checkbox to false.

The Code is as follows:

Script document. getElementById ("chk_uninfound"). checked = false; script

This code can meet this requirement in firefox and other browsers. vidu cannot live or die in IE. This check is checked every time, whether it is Refresh or backward.
Is this code in IE not working?
Verify that an alert is added before and after the script. It is found that the checkbox is not selected before and after the checked = false is executed. When the warning box is confirmed, this check box appears!
This indicates that in the subsequent page loading sequence, an event sets this checkbox to true. First, try to execute this script in the onload of the page.

The Code is as follows:

Window. onload = function (){
Alert ("before ");
Document. getElementById ("chk_uninfound"). checked = false;

We found that this check box was selected when executing alert ("before");, which means that this check box was automatically selected by the browser before the onload event, the specific reason involves the internal mechanism of IE.
Register this function in the onload event. This requirement is met here.
However, onload is executed only after all the elements on the page are loaded. During the local test, a request returns slowly, so that the onload event cannot be executed, this is something we don't want to see.
Later I found that another checkbox on the Website won't save the previous status when the page is refreshed. After careful comparison, I found that this input has one more checked = "" attribute:

With this attribute, the event does not need to be placed in onload.
Next, perform the following experiments:

The Code is as follows:

This checkbox can't be inapplicable

This checkbox can be inbuilt

// Window. onload = function (){
Var chks = document. getElementsByTagName ("input ");
For (var I = 0, l = chks. length; I Alert (chks [I]. id );
Chks [I]. checked = false;

For ease of description, the execution time of the above script is called t1, And the execution time of window. onload is called t3.
After adding alert, we found that:
Chk_unin1_chk_in1 _
Run the script in the script block:
Selected before t1
Selected after t1
The following code is executed in onload:
Selected before t3
Unselected after t3
After checked = "" is added, it is selected before t1 and then set as unchecked by t1.
Solution 1: Process in the onload event
Solution 2: add the checked attribute

<! Doctype html public "-// W3C // dtd html 4.01 Transitional // EN" ""> <HTML> <HEAD> <TITLE> New Document </TITLE> <META NAME = "Generator" CONTENT = "EditPlus"> <meta name = "Author" CONTENT = ""> <meta name = "Keywords" CONTENT = ""> <meta name = "Description "CONTENT =" "> </HEAD> <BODY> </HTML>
[Ctrl + A select all Note: If you need to introduce external Js, You need to refresh it to execute]

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

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.