さて、ダッシュコードでチェックボックスの状態をプログラムで変更しようとしています。私はもう試した:
var checkbox = document.getElementById("checkbox");
// I have tried all the following methods.
checkbox.checked = false;
checkbox.selected = false;
checkbox.value = false;
さて、ダッシュコードでチェックボックスの状態をプログラムで変更しようとしています。私はもう試した:
var checkbox = document.getElementById("checkbox");
// I have tried all the following methods.
checkbox.checked = false;
checkbox.selected = false;
checkbox.value = false;
ダッシュボードウィジェットはWebKitテクノロジーで実行されるだけなので、Safariで有効なコードはDashcodeでも有効である必要があります。次のいずれかが機能するはずです。
checkbox.checked = true;
checkbox.setAttribute("checked", "true");
それらが機能していないという事実は、コードの他の場所に問題があることを示しています。行を確認します
var checkbox = document.getElementById("checkbox");
checkbox
要素を変数に正しく割り当てます。また、「チェックボックス」要素のIDが有効で正しいことを確認してください(重複していない、タイプミスがないなど)。
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!
checkbox.setAttribute("checked", "checked"); // set
checkBox.removeAttribute("checked"); // remove
この質問はしばらく前からありました。とにかく、次のことがうまくいきます。
チェックボックス.childNodes[1].checked = true; checkBox.childNodes[1].checked = false;
前の回答で指摘したように、Dashcode がこれらのコントロールを作成する方法では、実際の ID (この例ではチェックボックス) を持つ div ラッパーを通過し、子ノード 1 である入力のプロパティを設定する必要があります。
ノードに割り当てられている ID を制御できないため、入力の実際の「ID」を探すのは問題があります。たとえば、2 つのチェックボックスがある場合、最初のチェックボックスには子ノード 1 の ID として「input」があり、2 番目のチェックボックスには「input1」があります。あなたのデザインはもう!
別の方法があるかもしれませんが、まだ見つけていません。
どのブラウザを使用したかわかりませんが、FF 3.6 でテストしたところ、動作しました。このように置くだけです:
checkbox.checked = false;
その間:
checkbox = document.getElementById('blablabla');
またはそのように書く
document.getElementById('idhere').checked = false;
多分:
checkbox.checked = "checked";
それで:
checkbox.checked = "unchecked";
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 に設定できます。