9

さて、ダッシュコードでチェックボックスの状態をプログラムで変更しようとしています。私はもう試した:

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

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

8 に答える 8

21

ダッシュボードウィジェットはWebKitテクノロジーで実行されるだけなので、Safariで有効なコードはDashcodeでも有効である必要があります。次のいずれかが機能するはずです。

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

それらが機能していないという事実は、コードの他の場所に問題があることを示しています。行を確認します

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

checkbox要素を変数に正しく割り当てます。また、「チェックボックス」要素のIDが有効で正しいことを確認してください(重複していない、タイプミスがないなど)。

于 2010-03-21T21:49:13.990 に答える
6

This question is one month old as I write this answer. It was probably already solved, but in any case I would like to add that if you are using Dashcode, the Checkbox part is a div which contains one label and one input, this one being the "real" checkbox.

If you inspect the html as it is loaded in Safari you will notice that "checkbox" is the type of the element.

Therefore the proper way to change the state of the checkbox would be, assuming "input" is its id (it could have a default number attached though):

document.getElementById("input").checked="true";

or whichever method you want to use.

The main point here is that you were trying to change the state of another div.

Hope it helps!

于 2010-04-23T11:25:15.260 に答える
2
checkbox.setAttribute("checked", "checked"); // set
checkBox.removeAttribute("checked"); // remove
于 2010-03-21T21:42:44.787 に答える
1

この質問はしばらく前からありました。とにかく、次のことがうまくいきます。

チェックボックス.childNodes[1].checked = true; checkBox.childNodes[1].checked = false;

前の回答で指摘したように、Dashcode がこれらのコントロールを作成する方法では、実際の ID (この例ではチェックボックス) を持つ div ラッパーを通過し、子ノード 1 である入力のプロパティを設定する必要があります。

ノードに割り当てられている ID を制御できないため、入力の実際の「ID」を探すのは問題があります。たとえば、2 つのチェックボックスがある場合、最初のチェックボックスには子ノード 1 の ID として「input」があり、2 番目のチェックボックスには「input1」があります。あなたのデザインはもう!

別の方法があるかもしれませんが、まだ見つけていません。

于 2011-11-01T12:54:11.903 に答える
1

どのブラウザを使用したかわかりませんが、FF 3.6 でテストしたところ、動作しました。このように置くだけです:

checkbox.checked = false;

その間:

checkbox = document.getElementById('blablabla');

またはそのように書く

document.getElementById('idhere').checked = false;
于 2010-12-08T08:27:38.323 に答える
0

多分:

checkbox.checked = "checked";

それで:

checkbox.checked = "unchecked";
于 2010-03-21T21:35:25.223 に答える
0
cell = row.insertCell(-1);
sel = document.createElement('input');
sel.setAttribute("type", "checkbox")
sel.setAttribute("name", "myCheckBox")
cell.appendChild(sel);
cell.getElementsByTagName('input')[0].checked = true;

テーブル、行、セルを作成し、その中にチェックボックスを作成します。最初の入力オブジェクトをつかんで、checked ステータスを true に設定できます。

于 2015-07-16T14:47:04.397 に答える