Home >Web Front-end >JS Tutorial >How to determine whether a certain item is checked in js

How to determine whether a certain item is checked in js

anonymity
anonymityOriginal
2019-05-29 11:36:413542browse

js determines whether input checked is selected code example

checked attribute sets or returns whether the checkbox should be selected.

How to determine whether a certain item is checked in js

Syntax

checkboxObject.checked=true|false

This attribute saves the current state of the checkbox. Whenever this value changes, onclick The event handler will be triggered (the onchange event handler may also be triggered).

Example

The following example can set the status of the checkbox:

        <html>
        <head>
        <script type="text/javascript">
        function check()
          {
          document.getElementById("check1").checked=true
          }
        function uncheck()
          {
          document.getElementById("check1").checked=false
          }
        </script>
        </head>
        <body>
        <form>
        <input type="checkbox" id="check1" />
        <input type="button" onclick="check()" value="Check Checkbox" />
        <input type="button" onclick="uncheck()" value="Uncheck Checkbox" />
        </form>
        </body>
        </html>

The above is the detailed content of How to determine whether a certain item is checked in js. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:what is commonjsNext article:what is commonjs