Get the ID by Class name JQuery

前端 未结 8 1908
臣服心动
臣服心动 2021-02-05 19:00

Hi this is a jquery question:

supposed i have this:





        
相关标签:
8条回答
  • 2021-02-05 19:46

    try something like this, you don't need to iterate

            $(document).ready(function () {
                $("#submit").click(function(){
                      if($(".select").is(':checked')){
                          alert($(".select:checked").attr('id'));
                      }
                });
            });
    
    0 讨论(0)
  • 2021-02-05 19:56

    Are you only checking one checkbox at a time?

    alert( $(".select:checked").attr('id') );

    Or, if you have multiple checkboxes checked at once:

    $(".select:checked").each(function(){
       alert($(this).attr('id'));
    });
    

    Demo: http://jsfiddle.net/UTux2/

    0 讨论(0)
提交回复
热议问题