2016-10-23 11 views
0

選択後、選択したオプションを無効にしたい場所を選択しています。例: クロムで選択したオプションを無効にする

<select id="elementSelect" > 
 
<option>SVG Element</option> 
 
<option onClick=this.disabled=true;this.innerHTML='&check;circle' >circle</option> 
 
<option onClick=this.disabled=true;this.innerHTML='&check;ellipse' >ellipse</option> 
 
<option onClick=this.disabled=true;this.innerHTML='&check;rect' >rect</option> 
 
</select>

これはOK作品IEとFFですが、ChromeはonClickイベントを無視します。 アイデアありがとう。

onclickの

答えて

1

()イベントは、オプションを特定し、それにdisabled属性を追加する<option>

使用querySelectorによってサポートされていません。

希望すると便利です。

var select = document.getElementById('elementSelect') 
 
select.onchange = function(e){ 
 
    var val = e.target.value 
 
    var el = document.querySelector('select option[value=\''+val+'\']') 
 
    el.innerHTML = '✓'+val 
 
    el.setAttribute('disabled','disabled') 
 
}
<select id="elementSelect"> 
 
    <option value="SVG Element">SVG Element</option> 
 
    <option value="circle">circle</option> 
 
    <option value="ellipse">ellipse</option> 
 
    <option value="rect">rect</option> 
 
</select>

+0

素晴らしい作品!ありがとう。 –

+0

@FrancisHemsherよろしくお願いします! –

関連する問題