私は、HTML、CSS、JavaScript、jQueryを使ってrubik cubeを解くシステムを開発しようとしています。selectElement.value not working
あなたはでそれを見ることができます。問題は、以下の機能である rubik fiddle
:
function processFile(e) {
var selects;
var file = e.target.result,
results;
if (file && file.length) {
var i, j, lines = file.split("\n");
selects = document.getElementById("main").getElementsByTagName("select");
for (i = 0; i < 6; i++) {
for (j = 0; j < 9; j++) {
selects[i*9+j].value = lines[i].split(" ")[j];
}
}
}
}
selects[i*9+j].style.backgroundColor = lines[i].split(" ")[j];
に、我々は、以下の行を変更した場合
selects[i*9+j].value = lines[i].split(" ")[j];
それは問題なく動作していますが、背景色ではなく値を変更する必要があります。ここで
は、select要素の一つである:事前に
lines = "yellow white white white red white white white white white white white white blue white white white white white white white white orange white white white white white white white white green white white white white white white white white white white green white white orange white white white yellow white white white white ";
ありがとう:ここ
<select class="cell 00">
<option class="colorOption" value="white" title="white" style="background-color: white;"></option>
<option class="colorOption" value="red" title="red" style="background-color: red;"></option>
<option class="colorOption" value="blue" title="blue" style="background-color: blue;"></option>
<option class="colorOption" value="orange" title="orange" style="background-color: orange;"></option>
<option class="colorOption" value="green" title="green" style="background-color: green;"></option>
<option class="colorOption" value="yellow" title="yellow" style="background-color: yellow;"></option>
</select>
はラインのサンプル値です!
更新:問題は解決されました。次の行追加して :私はちょうど(J = 4を!選び、中央を除く):変更をトリガしなければならなかった
if (j != 4) {
$(selects[i*9+j]).trigger('change');
}
を次のようにjsの変更機能は次のとおりです。
function processFile(e) {
var selects;
var file = e.target.result,
results;
if (file && file.length) {
var i, j, lines = file.split("\n"), colors;
selects = document.getElementById("main").getElementsByTagName("select");
for (i = 0; i < 6; i++) {
for (j = 0; j < 9; j++) {
selects[i*9+j].value = lines[i].split(" ")[j];
if (j != 4) { //added this lines
$(selects[i*9+j]).trigger('change'); //added this lines
} //added this lines
}
}
}
}
ありがとうございました!
jqueryについては、 – guradio
jQueryを使用してselect要素とオプションを作成しました。https://jsfiddle.net/shubhamkundu/ytcek085/1/ –
'.getElementById(" main ")。getElementsByTagName(" select ");' ???あなたは間違いをしていませんか?もしそうなら、彼らは何ですか? – zer00ne