您可以在服务器上执行此操作:
public ActionResult SaveImageId(string imageId)
{
//Process your image id somewhere
//If successful
return Json(new { success = true }, JsonRequestBehaviours.AllowGet);
}
在客户端:
$(".sendImage").change(function(){
var imageId = $(this).is(":checked")
? $(this).siblings('img').attr("id")
: null;
if(imageId) sendRequest(imageId);
});
//Send the image id to your controller endpoint
function sendRequest(imageId) {
$.get('@Url.Action('SaveImageId')' + '?imageId=' + imageId, function(){
//show a loading gif maybe
});
}
//Your html
<div>
<img id="9" class="thumb" src="/Content/uploads/Jellyfish.jpg">
<input type='checkbox' class='sendImage' />
</div>
<div>
<img id="10" class="thumb" src="/Content/uploads/Lighthouse.jpg">
<input type='checkbox' class='sendImage' />
</div>
<div>
<img id="11" class="thumb" src="/Content/uploads/Chrysanthemum.jpg">
<input type='checkbox' class='sendImage' />
</div>