2017-06-01 98 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