Correct way to do HTML5 checkbox

前端 未结 2 1006
醉话见心
醉话见心 2021-02-02 05:52

I can\'t seem to find an example anywhere... what\'s the correct way of doing a HTML5 checkbox?

2条回答
  •  醉话见心
    2021-02-02 06:28

    A more complete example - and avoiding the long stream of posts to How to check whether a checkbox is checked in jQuery?.

    HTML

    
    

    Optionally add the 'checked' attribute to default to checked on load.

    
    

    JavaScript

    $('#your_id').is(':checked')        // Returns a Boolean TRUE if checked
    

    e.g.

    if ($('#your_id').is(':checked')) {
        // Checkbox was checked
    }
    

提交回复
热议问题