JavaScript页面回发失败

时间:2014-05-28 08:24:18

标签: javascript asp.net

我有这个脚本给我的按钮效果,它在页面回发后失败,我也把代码放在pageLoad方法中但它仍然无法正常工作。任何想法如何在页面加载后使该脚本运行。

$(document).ready(function () {

            /*preloader for image loading bar*/

            jQuery(function ($) {
                function preLoad() {
                    //alert("script running");
                    $("#divQuestionMatrix").addClass("hidden");
                }

                function loaded() {
                    $("#divQuestionMatrix").removeClass("hidden");
                    $('div#preLoader').css({ display: 'none' }).remove();
                }

                preLoad();
                window.onload = loaded;
            });

            /* End of preloader*/



            $("#btnPrevious").click(function (e) {
                $("#navigation").val("previous");
            }
            );
            $("#btnNext").click(function (e) {
                $("#navigation").val("next");
            }
            );

            /* $(".qmatrix").click(function () {
            //get id of button
            alert($(this).attr('id'));
            $("#navigation").val($(this).attr('id'));
            }
            );*/

            $(".qmatrix").hover(function (e) {
                //get id of button
                //alert($(this).attr('id'));
                //get src of image before hover
                var origimage = $(this).attr('src');
                // alert(origimage);
                //$(this).attr({ src: 'images/questionMatrix/100' + $(this).attr('id') + '.png' });
                $(this).stop().animate({ "opacity": "0.1" }, "fast")
            },
            function () {
                // $(this).attr({ src: '' + origimage.toString() + '' });
                $(this).stop().animate({ "opacity": "1" }, "fast");
            }
    );

2 个答案:

答案 0 :(得分:1)

页面加载完成后会触发document.ready事件。

在ready事件的处理程序中,您将使用ready事件快捷方式(将函数直接传递给全局jQuery函数(与全局$函数btw相同)以添加另一个处理程序准备事件的功能。

在第二个就绪处理程序中,您将尝试将已加载的函数分配给window.onload,此时此点已被触发。

答案 1 :(得分:0)

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>

将此最新的Jquery库放在您的document.ready()函数的上方,然后尝试运行您的程序。

相关问题