Changing a checkbox's state programmatically in dashcode

前端 未结 8 1460
一个人的身影
一个人的身影 2021-02-15 01:22

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 02:14

    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).

提交回复
热议问题