【问题标题】:Check HTML page for particular table ID and element using jQuery使用 jQuery 检查 HTML 页面的特定表格 ID 和元素
【发布时间】:2012-05-28 20:52:35
【问题描述】:

jQuery 是否有一种方法可以确定特定表格是否存在于 HTML 文档中以及 alert();me 它是否存在?

我在文档中查找的特定表的存在是:

<table id="main_table"

【问题讨论】:

    标签: javascript jquery html html-table exists


    【解决方案1】:
    $(function() {
        // after dom ready
    
        if($('table#main_table').length){
          alert('exists');
        }
    
    })
    

    【讨论】:

    • 非常令人钦佩的响应时间先生。 :)
    【解决方案2】:

    在domready 活动中查看

    $(function() {
        if ($('#main_table').length) { ... /* element exists */ }
    
        /** 
         * or - without passing again through jQuery function -
         * if (document.getElementById('main_table')) { ... }
         */
    });
    

    【讨论】:

      【解决方案3】:
      $(document).ready(function() {
           $("#check").click(function() {
               if($('table#main_table').length){
                alert('Table Exists');
              }
          });
      });
      

      ​

      示例: http://jsfiddle.net/ipsjolly/3nVrZ/2/

      【讨论】:

      • 嗨。感谢您的意见,但我不确定您为什么在此处添加 .click。
      • 如果需要,它会在检查页面上的所有表格后向您显示警报。请检查答案中给出的链接
      猜你喜欢
      • 2010-11-15
      • 2019-09-06
      • 2012-05-11
      • 2013-06-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多