日期:2014-05-18  浏览次数:20429 次

关于updatepanel回传之后JS失效问题!!!!!!!!!!!!!!!!!!!
我找了写资料,貌似是应为UpdatePanel来回往返不会保留 Javascript 或其他客户端技术(如 Adobe Flash)生成的任何效果。
我也找到了解决办法:
http://msdn.microsoft.com/zh-cn/library/bb311028.aspx
http://hi.baidu.com/a_longge2009/blog/item/9956cb23ca971ea94723e849.html
其实就是用Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(BeginRequestHandler);
但是我试了,貌似不行啊....是不是我的JS有问题???我对JS不大懂,请大家帮帮忙!!
HTML code

function lr(overHide, scrollUl, leftBtn, rightBtn, num) {
                    var doc = document,
                    overHide = doc.getElementById(overHide),
                    scrollUl = doc.getElementById(scrollUl),
                    liArr = scrollUl.getElementsByTagName('li'),
                    len = liArr.length,
                    leftBtn = doc.getElementById(leftBtn),
                    rightBtn = doc.getElementById(rightBtn),
                    overWidth = overHide.offsetWidth;
                    scrollUl.style.width = len * num + 'px';
                    var inWidth = scrollUl.offsetWidth;
                    function checkBtn(overHide, scrollUl, leftBtn, rightBtn) {//判断左右按钮显示与隐藏
                        if (overWidth >= inWidth) {//内容不够不需要左右按钮
                            leftBtn.style.visibility = 'hidden';
                            rightBtn.style.visibility = 'hidden';
                        } else if (overHide.scrollLeft == 0) {//右显示左隐藏
                            leftBtn.style.visibility = 'hidden';
                            rightBtn.style.visibility = 'visible';
                        } else if ((overHide.scrollLeft + overWidth) == inWidth) {//左显示右隐藏
                            leftBtn.style.visibility = 'visible';
                            rightBtn.style.visibility = 'hidden';
                        } else if ((overHide.scrollLeft + overWidth) < inWidth && overHide.scrollLeft > 0) {//左右均显示
                            leftBtn.style.visibility = 'visible';
                            rightBtn.style.visibility = 'visible';
                        }

                    }
                    checkBtn(overHide, scrollUl, leftBtn, rightBtn);
                    function stepL(obj, step) {
                        var n = 0;
                        function scrollL(obj, step) {
                            if (n < step) {
                                obj.scrollLeft += 5;
                                n += 5;
                            } else {
                                clearTimeout(comeon)
                            }
                            checkBtn(overHide, scrollUl, leftBtn, rightBtn)
                            var comeon = setTimeout(function () { scrollL(obj, step) }, 20);
                        }
                        scrollL(obj, step);
                    }
                    function stepR(obj, step) {
                        var n = step;
                        function scrollR(obj, step) {
                            if (n > 0) {
                                obj.scrollLeft -= 5;
                                n -= 5;
                            } else {
                                clearTimeout(comeon)
                            }
                            checkBtn(overHide, scrollUl, leftBtn, rightBtn)
                            var comeon = setTimeout(function () { scrollR(obj, step) }, 20);
                        }
                        scrollR(obj, step);
                    }
                    leftBtn.onclick = function () {
                        stepR(overHide, num)
                    }
                    rightBtn.onclick = function () {
                        stepL(overHide, num)
                    }
                }
                lr('scroll_cont', 'scroll_ul', 's_L', 's_R', 122);



------解决方案--------------------