2012-10-29 138 views
1

我有一些单选按钮:检查是否单选按钮中的一个项目检查

<input type="radio" id="rdoLevel" name="rdoSelect" /> 
<input type="radio" id="rdoBase" name="rdoSelect" /> 
<input type="radio" id="rdoSchool" name="rdoSelect" /> 
<input type="radio" id="rdoTypeRegistre" name="rdoSelect" /> 

,我想检查由ID的每个项目,例如我想检查rdoLevel等于检查一些代码例如进行 像这样:

$("input:radio").click(function() { 
        var id = $(this).attr("id"); 
        if (id == "rdoLevel") { 
         //some code 
        } 
       }); 

我该怎么做?
谢谢你的建议!

回答

2
$("input:radio").click(function() { 
       var id = $(this).attr("id"); 
       if (id == "rdoLevel" && $(this).is(':checked')) { 
        //some code 
       } 
      }); 
4
$("input[name='rdoSelect']").change(function() { 
    switch (this.id) { 
     case "rdoLevel": 
      // ... 
      break; 
     case "rdoBase": 
      // ... 
      break; 
     // etc 
    } 
});​ 

DEMO:http://jsfiddle.net/kQC9L/

1

更改您点击以下。 (类型选择器不正确。)

$("input[type=radio]").click(function() { 
    var id = $(this).attr("id"); 
    alert(id); 

});​ 
相关问题