如何从ScriptManager.RegisterStartupScript调用javascript函数?

如何从ScriptManager.RegisterStartupScript调用javascript函数?,javascript,asp.net,vb.net,Javascript,Asp.net,Vb.net,我有以下javascript代码: <script type="text/javascript" language="javascript"> $(document).ready( function () { // THIS IS FOR HIDE ALL DETAILS ROW $(".SUBDIV table tr:not(:first-child)").not("tr tr"

我有以下javascript代码:

<script type="text/javascript" language="javascript">
        $(document).ready(
            function () {
                // THIS IS FOR HIDE ALL DETAILS ROW
                $(".SUBDIV table tr:not(:first-child)").not("tr tr").hide();
                $(".SUBDIV .btncolexp").click(function () {
                    $(this).closest('tr').next('tr').toggle();
                    //this is for change img of btncolexp button
                    if ($(this).attr('class').toString() == "btncolexp collapse") {
                        $(this).addClass('expand');
                        $(this).removeClass('collapse');
                    }
                    else {
                        $(this).removeClass('expand');
                        $(this).addClass('collapse');
                    }
                });

                function expand_all() {
                    $(this).closest('tr').next('tr').toggle();
                    };
            });

    </script>

你能帮我吗

您的方法
expand\u all
仅存在于
$(文档)中的函数范围内。ready(…)
,为了从
ScriptManager.RegisterStartupScript调用它,它需要在窗口级别,只需将该函数移到
$(文档)之外。ready(…)


$(文件)。准备好了吗(
函数(){
....                
});
函数expand_all(){
$(this).closest('tr').next('tr').toggle();
};

因为在匿名
$事件上下文中定义了
expand\u all
函数。把你的代码放在外面,它应该可以工作

function expand_all(){
    alert('test B');
}
$(document).ready(
    function () {
        // this won't work
        function expand_all() {
            alert('test A');
        };
    });


// will show test B
expand_all();
选中此项:


至于使用的参数,它们将这些内容隐藏在;)
<script type="text/javascript" language="javascript">
    $(document).ready(
        function () {
           ....                
        });

    function expand_all() {
           $(this).closest('tr').next('tr').toggle();
    };
</script>
function expand_all(){
    alert('test B');
}
$(document).ready(
    function () {
        // this won't work
        function expand_all() {
            alert('test A');
        };
    });


// will show test B
expand_all();