私の javascript スキルは最高ではありませんが、最近取り組んでおり、やりたかったことの 1 つは、html オプション タグの属性を設定することでした。プロジェクトを jfiddle に投稿して、少し見やすくしました。ここでそれを見ることができます。私はコードが1行ずれているだけだと思います。
選択した属性をオプション 2 から削除し、選択した属性をオプション 1 に作成するにはどうすればよいですか? つまり、「another-popup」を開くと、オプション 2 ではなくオプション 1 が選択されるようになります。
jsFiddle リンクを確認することをお勧めしますが、この質問にもコードを投稿しました。更新リンクの JavaScript:
function updateSelected(id, removeID, parentID) {
document.getElementById(parentID).style.display = 'none';
document.getElementById(id).setAttribute("selected","selected");
document.getElementById(removeID).removeAttribute("selected")
}
html:
<a href="#box" rel="popup">Popup</a>
<div id="box" class="popup">
<a href="#another-box" rel="popup" onClick="updateSelected("1", "2", "box");">Another box</a>
</div>
<div id="another-box" class="popup">
<form>
<select>
<option id="1">option 1</option>
<option id="2" selected>option 2</option>
</select>
</form>
</div>
助けてくれてありがとう