ASP.NET MasterPage javascript错误

时间:2012-11-27 06:35:01

标签: javascript asp.net master-pages

我有这个javascript:

<script type="text/javascript">
            $(document).ready(function () {
                $('#social-share').dcSocialShare({
                    buttons: 'twitter,facebook,linkedin,digg,stumbleupon,delicious,pinterest,buffer,print,email',
                    offsetLocation: 0,
                    center: 625,
                    floater: false
                });
                var a = $('#dcssb-1');
                buttonPosition(a);
                $(window).scroll(function () {
                    buttonPosition(a);
                });
            });
            function buttonPosition(obj) {
                var top = $(document).scrollTop();
                var p = top > 400 ? { marginTop: '20px' } : { marginTop: (400 - top) + 'px' };
                obj.css(p);
            }
</script>

当我将代码放在MasterPage或使用母版页的页面中时,我收到此错误:

Object doesn't support property or method 'dcSocialShare' 

我已将所有JS包含正确放置在页面中,但是当我在没有materpage的情况下使用它时,为什么只有当它放在母版页或使用母版页的页面中时才会出现此错误?

1 个答案:

答案 0 :(得分:1)

尝试将您的js文件包含在asp:ScriptManager中,如下所示

<asp:ScriptManager ID="ScriptManager1" runat="server">
    <Scripts>
        <asp:ScriptReference Path="~/jquery.js" />
    </Scripts>
</asp:ScriptManager>