Changing a checkbox's state programmatically in dashcode

前端 未结 8 1618
长发绾君心
长发绾君心 2021-02-15 01:28

Okay, so I\'m trying to change a checkbox\'s state programmatically in dashcode. I\'ve tried:

var checkbox = document.getElementById(\"checkbox\");

// I have tr         


        
8条回答
  •  醉酒成梦
    2021-02-15 01:59

    Dashboard Widgets just run on WebKit technologies, so code valid for Safari should also be valid in Dashcode. Either of the following should work:

    checkbox.checked = true;
    checkbox.setAttribute("checked", "true");
    

    The fact that they are not working indicates there is a problem elsewhere in your code. I would check the line

    var checkbox = document.getElementById("checkbox");     
    

    Correctly assigns an element to the checkbox variable. Also, check the id of your "checkbox" element is valid and correct (not a duplicate, doesn't have a typo, etc).

提交回复
热议问题