开发者

Select an element based on two attributes

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; 
 } 
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜