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

我怎样才能做到这一点?
谢谢你的建议!

4

3 回答 3

4
$("input[name='rdoSelect']").change(function() {
    switch (this.id) {
        case "rdoLevel":
            // ...
            break;
        case "rdoBase":
            // ...
            break;
        // etc
    }
});​

演示:http: //jsfiddle.net/kQC9L/

于 2012-10-29T14:48:39.300 回答
2
 $("input:radio").click(function () {
                var id = $(this).attr("id");
                if (id == "rdoLevel" && $(this).is(':checked')) {
                    //some code
                }
            });
于 2012-10-29T14:48:31.003 回答
1

将单击更改为以下内容。(类型选择器不正确。)

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

});​
于 2012-10-29T14:49:10.643 回答