Prevent checkbox from ticking/checking COMPLETELY

前端 未结 13 591
醉梦人生
醉梦人生 2020-12-09 07:48

I have been asked to disable the \"ticking\" of a checkbox. I am not being asked to disable the checkbox, but to simply disable the \"ticking\".

In other w

13条回答
  •  不思量自难忘°
    2020-12-09 07:57

    TL:DR;

    HTML api's execute before JavaScript. So you must use JavaScript to undo HTML's changes.

    event.target.checked = false
    

    WHAT is the problem?

    Strictly speaking: we cannot "stop" the checkbox from being ticked. Why not? Because "being ticked" exactly means that the DOM's, HTML element has a checked property value of true or false, which is immediately assigned by the HTML api

    console.log(event.target.checked) // will be opposite of the previous value
    

    So it's worth explicitly mentioning this HTML api is called before scripts. Which is intuitive and should make sense, because all JavaScript files are themselves the assignment of a

提交回复
热议问题