如何使用jQuery获取按钮单击时所有选中复选框的ID

<html>  
    <input type='checkbox' id='1' name='checkMr[]' value='1' />       
    <input type='checkbox' id='2' name='checkMr[]' value='2' />            
    <input type='checkbox' id='3' name='checkMr[]' value='3' />         
    <input type='checkbox' id='4' name='checkMr[]' value='4' />        

    <a id="savedoctorschedule" style="float: right;" class="clyes clbutton clbtnSave">Save</a>       
</html> 

<script>
$j("#savedoctorschedule").bind("click", function () { 
    $j.ajax({
        url: "schedulemr.php",
        type: "post",
        data: { schmrid: $j("#sel_mr").val(), 
        schedocid: $j("#checkMr[]").val(), 
        schedate: $j("#date1").val(), },
        success:function(response){         
        }
</script>

<?php
include '../includes/include.php';
$schmrid = $_POST['sel_mr'];
$schedate = $_POST['date1'];
$schedocid = $_POST['checkMr'];
foreach($schedocid as $a => $b)
{
   $sql="INSERT INTO tbl_mr_schedule(doctor_idscheduled_date) 
   VALUES ('".$schedocid[$a]."','".$schmrid."','0','".$date."','".$schedate."');";
   mysql_query($sql) or die(mysql_error());
}
header('Location:../visitplan/');
?>

I want all the ids of checked checkboxes using jQuery; the checkbox may be n number. I want to insert the checked checkboxes' value in the database where the number of records will depend upon the number of checked checkbox. This would be using PHP as server-side script.

How can I fix it?

Your document is invalid for several reasons. Skipping the obvious (missing doctype/<body>/etc), the id attribute may not begin with a number; id="1" is invalid. You'll have to use a non-numeric prefix like id="check-1" or by assigning the ID as the value of the checkbox.

Once you've fixed this, you can use the following to find all checked checkboxes, and retrieve their value (or whichever attribute you choose to use).

$("input:checked").map(function () { return $(this).val(); });

Try below,

$(':checkbox[name="checkMr[]"]:checked') //returns you the list of selected checkbox

then you can,

var selectedID = [];
$(':checkbox[name="checkMr[]"]:checked').each (function () {
    selectedID.push(this.id);
});

DEMO

Id's cannot start with numbers. Once you've updated the id's use attr('value') or .val() to retrieve the value associated with the input.

$("#savedoctorschedule").click(function(e){
    e.preventDefault();
    var sList = "";
    $('input[name="checkMr[]"]').each(function () {
        if(this.checked){
            sList += "(" + $(this).attr('id') + ")";
        }
    });
    alert(sList);
    }
);​

Please find the FIDDLE