foreach object/array in jQuery

后端 未结 5 2009
滥情空心
滥情空心 2021-02-08 15:02

I have a problem, i have X in my code, now I want to foreach this object/array its out put. - look my code.

$(\"#d         


        
5条回答
  •  無奈伤痛
    2021-02-08 15:26

    When I got you right, you want the user to select one checkbox (or is it one or more?). This should do it:

    $("#denied_seekrs").click(function()
    { 
    
        var $checkedInputs = $("input:checked"); 
    
        if ($checkedInputs.length != 1) 
        { 
            alert ("Please select one event"); 
            return false; 
        } 
    
        alert( $checkedInputs.val() ); //submit the form 
    }); 
    

    EDIT: After reading your question again, I realized that the above code does not answer your question. However, the above does work and is a much shorter version of your solution. Maybe you want to use it instead. To answer your question, you could alert the value of all checked boxes like this:

    Change this:

        alert( $checkedInputs.val() ); //submit the form 
    

    to this:

        var values = "";
        $checkedInputs.each(function(){
          values += $(this).val() + " ";
        });
    
        alert( values );
    

提交回复
热议问题