2012-05-22 48 views

回答

8
$(function() { 
    // after dom ready 

    if($('table#main_table').length){ 
     alert('exists'); 
    } 

}) 
+1

非常令人佩服的响应时间先生。 :) – derek8

2

domready事件只是检查

$(function() { 
    if ($('#main_table').length) { ... /* element exists */ } 

    /** 
    * or - without passing again through jQuery function - 
    * if (document.getElementById('main_table')) { ... } 
    */ 
}); 
1
$(document).ready(function() { 
    $("#check").click(function() { 
     if($('table#main_table').length){ 
      alert('Table Exists'); 
     } 
    }); 
}); 

防爆充足:http://jsfiddle.net/ipsjolly/3nVrZ/2/

+0

嗨。感谢您的输入,但我不确定您为什么包含.click这里。 – derek8

+1

它会显示您检查页面上的所有表后,如果需要可用或不.Plz检查答案中给出的链接 –