I have an element like this
<input type='select' class='MultiSelect' id='myId'>
Now I want to get v开发者_如何学运维alue of a selectbox where it must have MultiSelect class and Also Must have myid id.
How to do this ?
Thanks
with jQuery $('#myid.MultiSelect').val()
JavaScript only solution, no jQuery : http://jsfiddle.net/XFCzN/ But see how beautiful it looks with jQuery.
<input type='select' class='OtherClass' id='myid' value='no' >
<input type='select' class='MultiSelect' id='myid' value='yes' >
<input type='select' class='MultiSelect' id='nomyid' value='no' >
Script :
var reqInput = getByTwo("INPUT","MultiSelect","myid");
if(reqInput != null)
alert(reqInput.value);
else
alert("No Match");
function getByTwo(tagName,myClass,myId)
{
var myInputs = document.getElementsByTagName(tagName);
for(var i=0;i< myInputs.length;i++)
{
if((myInputs[i].getAttribute('class') == myClass) && (myInputs[i].id == myId))
return myInputs[i];
}
return null;
}
精彩评论