javascript-检查正在使用的表

javascript-检查正在使用的表,javascript,jquery,if-statement,jquery-plugins,Javascript,Jquery,If Statement,Jquery Plugins,我有两个表,只有一个javascript函数与这两个表关联。我想创建一个案例差异,以便根据选择的表,通过IF语句运行不同的方法 这是我的代码: <table id="table1" notip="true" class="dataTable no-footer" ...> <thead></thead> <tbody> <tr><td></td></tr> </tbody&g

我有两个表,只有一个javascript函数与这两个表关联。我想创建一个案例差异,以便根据选择的表,通过IF语句运行不同的方法

这是我的代码:

<table id="table1" notip="true" class="dataTable no-footer" ...>
  <thead></thead>
  <tbody>
    <tr><td></td></tr>
  </tbody>
</table>

这就是我的想法。 有没有人对如何做有想法,或者有更好的想法


Luca

此条件将始终为false,两个jQuery对象永远不相同

if ( $(this) === $('#table1') ) {
您可以比较底层DOM节点

if ( this === $('#table1').get(0) ) {
甚至只需要ID,或者使用jQuery的
is()

全部

(function($) {
    $.fn.recalculateTabOrder = function() {
        if (this.id === 'table1') addTable_1_Item();
        if (this.id === 'table2') addTable_2_Item();
    }
})(jQuery);

此条件将始终为false,因为两个jQuery对象从不相同

if ( $(this) === $('#table1') ) {
您可以比较底层DOM节点

if ( this === $('#table1').get(0) ) {
甚至只需要ID,或者使用jQuery的
is()

全部

(function($) {
    $.fn.recalculateTabOrder = function() {
        if (this.id === 'table1') addTable_1_Item();
        if (this.id === 'table2') addTable_2_Item();
    }
})(jQuery);

您的逻辑应该在什么时候工作:一些用户单击或选择事件或页面加载本身?您还应该将
Jquery
添加到此问题的标记中…您的逻辑应该在什么时候工作:一些用户单击或选择事件或页面加载本身?您还应该将
Jquery
添加到此问题的标记中问题…您的逻辑应该在什么时候工作:某些用户单击或选择事件或页面加载本身?您还应该将
Jquery
添加到此问题的标记中。。。