選択されている場合、選択要素にアクセスするにはどうすればよいですか?
var select = document.getElementById("select");
if(select.selected == true)
doesnt work any idea?
選択されている場合、選択要素にアクセスするにはどうすればよいですか?
var select = document.getElementById("select");
if(select.selected == true)
doesnt work any idea?
DOMツリーは次のようなものです
Select
|-option
|-option
`-option
選択できるのは選択ノードではありません。そのため、選択を取得し、子を参照し、子が選択されているかどうかを見つけるまでテストする必要があります。
document.getElementById( "mySelect")。value
また
var selObj = document.getElementById( "mySelect"); selObj.options [selObj.selectedIndex] .value;