Settings for CheckBox indeterminate state in HTML

Source: Internet
Author: User

The experience to share is the indeterminate state of the check box, and the check boxes in HTML are:

<input id= "CB" type= "checkbox"/>

Generally encountered check box may only need to select or not select two states can be, but sometimes a third type of uncertainty is required, such as when you do a cascading menu with a check box, when multiple check boxes for a child menu are partially selected, the check boxes of the parent menu should be in an indeterminate state to reflect the partial selection of the submenu.

The method is to set the indeterminate property of the checkbox through JS, and setting this property in the label is invalid.

<script>

function init () {

Chkbox = document.getElementById ("CB");

}

function Fun1 () {

Chkbox.indeterminate = false;

Chkbox.checked = true;

}

function fun2 () {

Chkbox.indeterminate = false;

chkbox.checked = false;

}

function Fun3 () {

Chkbox.indeterminate = true;

}

</script>

<body onload= "init ()" >

<input id= "CB" type= "checkbox"/>

<button onclick= "fun1 ()" > Check </button>

<button onclick= "fun2 ()" > Not selected </button>

<button onclick= "Fun3 ()" > Part selected </button>

</Body>

In addition, the checkbox's properties are checked, as long as the checked is set in this tab, the checkbox is selected when initialized, including not limited to four types:

Checked= "true"

Checked= "false"

Checked= ""

Checked

So, if you want to initially display as unchecked, do not set the Checked property.

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.