在dashcode中以编程方式更改复选框的状态 [英] Changing a checkbox's state programmatically in dashcode

查看:123
本文介绍了在dashcode中以编程方式更改复选框的状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧,所以我试图在dashcode中以编程方式更改复选框的状态。我试过:

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

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

// I have tried all the following methods.
checkbox.checked = false;
checkbox.selected = false;
checkbox.value = false;


推荐答案

Dashboard Widgets只是运行在WebKit技术上, for Safari也应该在Dashcode中有效。以下任一应该工作:

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");     

正确地为复选框分配一个元素 。此外,检查您的checkbox元素的id是否有效且正确(不是重复,没有拼写错误等)。

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

这篇关于在dashcode中以编程方式更改复选框的状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆