在asp.net中加载页面后执行javascript

在asp.net中加载页面后执行javascript,javascript,jquery,asp.net,pageload,Javascript,Jquery,Asp.net,Pageload,我有以下HTML标记: <asp:Image ID="imgMap" runat="server" ImageUrl="/common/images/harita.jpg" class="map" usemap="#Map" BorderWidth="0" /> <map name="Map" id="Map"> <area title="City1" shape="poly" coords="26

我有以下HTML标记:

 <asp:Image ID="imgMap" runat="server" ImageUrl="/common/images/harita.jpg" class="map"
            usemap="#Map" BorderWidth="0" />

        <map name="Map" id="Map">
            <area title="City1" shape="poly" coords="266,103" href="/dealer/186/Page.aspx#dealer1" />
            <area title="City2" shape="poly" coords="255,222"  href="/dealer/186/Page.aspx#dealer2" />            
</map>


.
.
.
.
Javascript代码如下所示:

 <script type="text/javascript">
        $(window).ready(function () {
            var addressSection = "",
             dealer = "",
             eTop = "",
            callbackAnimate = function () {
                setTimeout(function () {
                    $(dealer).removeAttr("style").fadeIn();
                }, 1000);
            },
             animateScroll = function () {
                 $('html, body').animate({ scrollTop: eTop }, 1000, function () {
                     $(dealer).effect("highlight", { color: "#fd9900" }, 500, callbackAnimate);
                 });
             };

            $('#Map').find('area').each(function (index, elArea) {
                $(this).click(function () {
                    addressSection = $(this).attr('href').split('#');
                    dealer = "#" + addressSection[addressSection.length - 1];
                    eTop = $(dealer).offset().top;
                    animateScroll();
                });
            });
        }); 
    </script>

$(窗口).ready(函数(){
var addressSection=“”,
交易商=”,
eTop=“”,
callbackAnimate=函数(){
setTimeout(函数(){
$(经销商).removeAttr(“风格”).fadeIn();
}, 1000);
},
animateScroll=函数(){
$('html,body')。动画({scrollTop:eTop},1000,函数(){
$(经销商).effect(“高亮显示”,“颜色:{fd9900”},500,callbackAnimate);
});
};
$('#Map')。查找('area')。每个(函数(索引,elArea){
$(此)。单击(函数(){
addressSection=$(this.attr('href').split('#');
经销商=“#”+addressSection[addressSection.length-1];
eTop=$(经销商).offset().顶部;
动画滚动();
});
});
}); 

我试图实现的是,当用户单击图像区域,页面转到href属性中指定的链接时,在页面加载后执行javascript代码,因此页面滚动到div部分。有了这段代码,滚动效果只有在页面加载后才起作用,但在用户第一次单击地图时就不起作用了。在地图点击上加载页面后,是否可以进行滚动?

您可以将其添加到小提琴中吗,如果您这样做,我将尽力提供帮助。很难理解您是想在页面加载时执行,还是第一次就失败了。@bitoiu Ok。这是JSFiddle链接,正如我所说,当我在页面上时,它可以工作,但当我从另一个页面提交时,它不会滚动。希望能更清楚的理解,让我看看。因此,您通常使用类似于page#city1的锚来导航此页面,您可能希望它向下滚动,但这只有在您已经在页面中并且单击地图正确时才会发生?@bitoiu是的,您已经很好地理解了。我想滚动效果也工作时,我来自其他网页。我想我必须更改href属性,并将delaer1和dealer2作为某种服务器变量传递。我只是在想,由于href属性的默认行为,在href属性中添加#dealer1总是会产生不必要的效果。另一个我认为可以做的是传递一个查询参数?city=X
 <script type="text/javascript">
        $(window).ready(function () {
            var addressSection = "",
             dealer = "",
             eTop = "",
            callbackAnimate = function () {
                setTimeout(function () {
                    $(dealer).removeAttr("style").fadeIn();
                }, 1000);
            },
             animateScroll = function () {
                 $('html, body').animate({ scrollTop: eTop }, 1000, function () {
                     $(dealer).effect("highlight", { color: "#fd9900" }, 500, callbackAnimate);
                 });
             };

            $('#Map').find('area').each(function (index, elArea) {
                $(this).click(function () {
                    addressSection = $(this).attr('href').split('#');
                    dealer = "#" + addressSection[addressSection.length - 1];
                    eTop = $(dealer).offset().top;
                    animateScroll();
                });
            });
        }); 
    </script>