选择特定的复选框值

时间:2014-04-06 15:19:46

标签: javascript jquery checkbox

我有一些名称相同的复选框,但每个复选框都有一个唯一值。 我想在任何单击特定复选框时获取该特定复选框的唯一值。

@foreach (var itert in Model.collec)
            {

                            @Html.CheckBox("chkResend",
                            new { @value = Html.Encode(itert.EventNumber), 
@class = "myclass" })

 };

jquery是:

$(document).ready(function () {    
    $(".myclass").click(function () {
        alert($(".myclass").attr("value"));
    });

});

我一直得到第一个复选框的值...

1 个答案:

答案 0 :(得分:1)

使用this keyword

$(document).ready(function () {
    $(".myclass").click(function () {
        alert(this.value); //this refers to the current element clicked
        // or alert($(this).attr("value"));
        // or alert($(this).val());
    });
});