2017-06-01 330 views
0

我有這個jquery,它會加載,當你點擊按鈕,但我希​​望它加載頁面加載時的函數。轉換點擊頁面加載jquery

 $("[src*=plus]").live("click", function() { 
      $(this).closest("tr").after("<tr><td></td><td colspan = '999'>" + $(this).next().html() + "</td></tr>") 
      $(this).attr("src", "images/minus.png"); 
     }); 

$("[src*=minus]").live("click", function() { 
     $(this).attr("src", "images/plus.png"); 
     $(this).closest("tr").next().remove(); 
    }); 

我已經使用這個嘗試,但它不工作:

$(document).ready(function() { 
     $(this).closest("tr").after("<tr><td></td><td colspan = '999'>" + $(this).next().html() + "</td></tr>") 
     $(this).attr("src", "images/minus.png"); 
    }); 

    $(document).ready(function() { 
     $(this).attr("src", "images/plus.png"); 
     $(this).closest("tr").next().remove(); 
    }); 
+1

您只使用一個$(文件)。就緒()和內部發生的一切。也是什麼版本的jQuery是這樣的?是不是已被棄用? – ThisGuyHasTwoThumbs

+0

不確定。這是我找到代碼的地方:https://www.aspsnippets.com/Articles/ASPNet-Nested-GridViews-GridView-inside-GridView-with-Expand-and-Collapse-feature.aspx –

+0

Live實際上[已移除截至1.9版本](http://api.jquery.com/category/removed/#post-409)。 –

回答

1

試試這個

$(document).ready(function() { 
    $("[src*=plus]").closest("tr").after("<tr><td></td><td colspan = '999'>" + 
    $("[src*=plus]").next().html() + "</td></tr>") 
    $("[src*=plus]").attr("src", "images/minus.png"); 
    $("[src*=plus]").attr("src", "images/plus.png"); 
    $("[src*=plus]").closest("tr").next().remove(); 
}); 
+0

謝謝!這工作! –

+2

@ThisGuyHasTwoThumbs做到了。感謝您的輸入 –

+0

@FurquanKhan偉大的將刪除我的評論:) – ThisGuyHasTwoThumbs