您必须以此来稍微更改html-
为两个复选框提供相同的类名。
<input type="checkbox" name="emailNotification" id="emailNotification"><label >Email Notification</label></input> <input type="checkbox" name="SharingNotification" id="SharingNotification"><label >File Sharing Notification</label></input>
现在,jQuery部分稍有变化-
$('.searchType').click(function() { alert($(this).attr('id')); //-->this will alert id of checked checkbox. if(this.checked){ $.ajax({ type: "POST", url: 'searchOnType.jsp', data: $(this).attr('id'), //--> send id of checked checkbox on other page success: function(data) { alert('it worked'); alert(data); $('#container').html(data); }, error: function() { alert('it broke'); }, complete: function() { alert('it completed'); } }); } });


