要素に ' ' を追加しようとしてselected
いますが、コードがまったく実行されません。
なぜ何か提案はありますか?
コードは次のとおりです。
$.post('./question_in_test.php',
{
questionId : vars[0]
} ,
function(data) {
$("#testQuestion > option").each(function () {
console.log("Something happens"); // Doesn't execute at all
if (this.value === data) {
$(this).prop('selected', 'selected');
}
});
console.log("NUmber id : " + data + " vars[0] : " + vars[0] ); // Shows on the console
}
);
PHP
ページには、select
データベースから取得したものがあります。
<select id = "testQuestion">
<optgroup label="Category 1">
<option>Option 1...</option>
</optgroup>
</select>
</select>