2016-11-30 131 views
0

我有一個選擇框具有多個選項屬性的選項。我也有一個隱藏變量。基於隱藏變量的值必須將其他選定屬性移除選項。從javascript中的選擇框中刪除選定的屬性

<option value="68" >A1</option> 
<option value="49" >A2</option> 
<option value="69" selected="selected">A3</option> 
<option value="59" selected="selected">A3</option> 
<option value="79" selected="selected">A3</option> 


<input type= hidden id="someId" value="69" /> 
基於隱性價值69

在本例中,我不得不刪除選定的屬性爲59和79

我能做到這一點jQuery的

$(".selected").removeAttr("selected"); 
var new_selection = $(this).find('option:selected'); 
new_selection.attr("selected",true).addClass(".selected"); 

但我想在JavaScript的。有沒有在JavaScript

+0

分享您的研究幫助大家做任何最好的辦法。告訴我們你試過了什麼,以及它爲什麼不符合你的需求。這表明你已經花時間去嘗試幫助自己,它使我們避免重申明顯的答案,最重要的是它可以幫助你得到更具體和相關的答案!另見[如何問](http://stackoverflow.com/questions/how-to-ask) – Cerbrus

+0

@Cerbrus對不起,我只是一個學習者在JavaScript – user2196474

回答

1
document.getElementsByClassName("selected").removeAttribute("selected"); 
var e = document.getElementById("asdf"); 
var strUser = e.options[e.selectedIndex].text; 
e.setAttribute("selected",true); 
e.classList.add("selected"); 

這只是解釋在JavaScript從您的jQuery代碼

相關問題