[英]Disable selected option in chrome
我有一個選擇,在選擇之后我要禁用其選擇的選項。 例如
<select id="elementSelect" > <option>SVG Element</option> <option onClick=this.disabled=true;this.innerHTML='✓circle' >circle</option> <option onClick=this.disabled=true;this.innerHTML='✓ellipse' >ellipse</option> <option onClick=this.disabled=true;this.innerHTML='✓rect' >rect</option> </select>
IE和FF可以正常運行,但Chrome會忽略onClick事件。 有任何想法嗎? 謝謝。
<option>
不支持onclick()事件
使用querySelector
標識選項並向其中添加disabled
屬性。
希望這可以幫助!
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>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.