2016-11-30 132 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代码

相关问题