$(document).ready(function() { if ($('#id').length) { // do something } }); 转载于:https://www.cnblogs.com/GeorgeWang/archive/2011/02/20/1958978.html