(only IE effective) about CheckBox three-state _ form effects

Source: Internet
Author: User
From:http://www.cnblogs.com/birdshome/archive/2005/01/03/85679.html
When we use the Windows XP Folder Properties dialog box, we find that the read-only and hidden options in the attributes category of the folder are sometimes not fully checked or unchecked states, It is often a state of being ticked, but the background is grey. In fact, this kind of indeterminate checkbox state Web can also be performed.

In a Web page, we can use the <input id= "chkb" type= "checkbox" > To get a CheckBox control. The most common form of this control is checked (ticked) or unchecked state, but we use the mouse to easily switch between these two states, but also can use scripting language to change their state, such as using JavaScript script:
Chkb.checked = true; or chkb.checked = false;
The following illustration shows the three states that a checkbox can perform:

The first and third are common, and they can be set using HTML, which means we can determine the initial state of a checkbox through the properties of an HTML element called checked. The indeterminate state we're talking about here, although it's supported at IE4.0, has no HTML element attribute to set its value, and can only use a script to set its indeterminate state.

For example, use JavaScript script (indeterminate default is False):

Chkb.indeterminate = true; or chkb.indeterminate = false;

Note: The checkbox's indeterminate is a separate property, regardless of the checkbox's checked, status value, which means it only affects the appearance of the checkbox. We can still use scripts to read checked and status values normally.
------------------------------------------------------------------------
From:http://www.itbody.com/doc/html/web/105537297.html
Copy Code code as follows:

<body>
<form name=test>
According to the onclick change of checkbox:<br>
<input type=checkbox name=checkbox0 flag=0 onclick= ' Gray (this) ' > initialized to unchecked checkbox<br>
</td><td><input type=checkbox name=checkbox1 flag=1 onclick= ' Gray (this) ' > initialized to White selected checkbox<br >
</td><td><input type=checkbox name=checkbox2 flag=2 onclick= ' Gray (this) ' > Initialized to Gray-selected checkbox<br >
According to the onpropertychange change of checkbox:<br>
<input type=checkbox name=checkbox3 onpropertychange= ' gray2 (this) ' > Initialized to unchecked checkbox
</form>
<script language=javascript>
For onclick, you need a custom attribute flag.
function Gray (c)
{
Switch (C.flag)
{
When flag is 0 o'clock, unchecked
Case ' 0 ': c.checked=true;c.indeterminate=true;c.flag= ' 2 ';
When the flag is not 1 o'clock, the white selected state
Case ' 2 ': c.checked=true;c.indeterminate=false;c.flag= ' 1 ';
When flag is 2 o'clock, the gray is selected
Case ' 1 ': c.checked=false;c.indeterminate=false;c.flag= ' 0 ';
}
}
For Onpropertychange
function Gray2 (c)
{
c.indeterminate=c.checked;
}
For the onload of the body, the state of the checkbox is judged according to the flag property of the checkbox
function Check ()
{
for (var i = 0;i<document.test.elements.length;i++)
{
var ele = document.test.elements[i];
if (ele.flag!=null)
{
if (ele.flag== ' 0 ')
{
ele.checked = false;
Ele.indeterminate = false;
}
if (ele.flag== ' 1 ')
{
Ele.checked = true;
Ele.indeterminate = false;
}
if (ele.flag== ' 2 ')
{
Ele.checked = true;
Ele.indeterminate = true;
}
}
}
}
Window.onload=check;
</script>



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: info-contact@alibabacloud.com 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.