【发布时间】:2012-05-28 20:52:35
【问题描述】:
jQuery 是否有一种方法可以确定特定表格是否存在于 HTML 文档中以及 alert();me 它是否存在?
我在文档中查找的特定表的存在是:
<table id="main_table"
【问题讨论】:
标签: javascript jquery html html-table exists
jQuery 是否有一种方法可以确定特定表格是否存在于 HTML 文档中以及 alert();me 它是否存在?
我在文档中查找的特定表的存在是:
<table id="main_table"
【问题讨论】:
标签: javascript jquery html html-table exists
$(function() {
// after dom ready
if($('table#main_table').length){
alert('exists');
}
})
【讨论】:
在domready 活动中查看
$(function() {
if ($('#main_table').length) { ... /* element exists */ }
/**
* or - without passing again through jQuery function -
* if (document.getElementById('main_table')) { ... }
*/
});
【讨论】:
$(document).ready(function() {
$("#check").click(function() {
if($('table#main_table').length){
alert('Table Exists');
}
});
});
【讨论】: