jQuery移动按钮元素href未链接到页脚

jQuery移动按钮元素href未链接到页脚,jquery,jquery-mobile,Jquery,Jquery Mobile,我正在使用jQuery移动框架构建一个移动站点,我相信我的按钮href属性不起作用,它是与标题中的站点品牌内联运行的菜单按钮 当用户使用以下代码单击时,该按钮应将用户发送到页面的页脚: <a data-role="button" href="#mainFooter" data-icon="arrow-d" data-iconpos="left" class="headerbutton">Menu</a> $(document).on("click", "#menu-bu

我正在使用jQuery移动框架构建一个移动站点,我相信我的按钮href属性不起作用,它是与标题中的站点品牌内联运行的菜单按钮

当用户使用以下代码单击时,该按钮应将用户发送到页面的页脚:

<a data-role="button" href="#mainFooter" data-icon="arrow-d" data-iconpos="left" class="headerbutton">Menu</a>
$(document).on("click", "#menu-button", function(event){
    $('html,body').animate({ scrollTop: $('#mainFooter').offset().top }, { duration: 'slow', easing: 'swing'});
});

然后在页脚中出现id为“mainFooter”的相应div标记:

<div id="mainFooter" name="mainFooter"></div>

我不明白为什么点击按钮时用户没有发送到页脚。请找到以下网页的链接

来自JQM文档->:

请注意:因为我们使用散列来跟踪导航历史记录 对于所有的Ajax“页面”,目前不可能深入链接到 jQueryMobile中页面上的锚(index.html#foo),因为 框架将查找ID为#foo而不是 滚动到具有该ID的内容的本机行为

您可能需要使用或类似工具实现自定义滚动

编辑

像这样的东西可能适合你:

$(document).delegate('.headerbutton', 'click', function(e){
    e.preventDefault();
    $("html, body").animate({ scrollTop: $('#mainFooter').offset().top }, 1000);
});
我希望这有帮助

来自JQM文档->:

请注意:因为我们使用散列来跟踪导航历史记录 对于所有的Ajax“页面”,目前不可能深入链接到 jQueryMobile中页面上的锚(index.html#foo),因为 框架将查找ID为#foo而不是 滚动到具有该ID的内容的本机行为

您可能需要使用或类似工具实现自定义滚动

编辑

像这样的东西可能适合你:

$(document).delegate('.headerbutton', 'click', function(e){
    e.preventDefault();
    $("html, body").animate({ scrollTop: $('#mainFooter').offset().top }, 1000);
});

我希望这有帮助

尝试将id属性(id=“menu button”)添加到菜单定位,并添加以下代码:

<a data-role="button" href="#mainFooter" data-icon="arrow-d" data-iconpos="left" class="headerbutton">Menu</a>
$(document).on("click", "#menu-button", function(event){
    $('html,body').animate({ scrollTop: $('#mainFooter').offset().top }, { duration: 'slow', easing: 'swing'});
});

尝试将id属性(id=“menu button”)添加到菜单定位,并添加以下代码:

<a data-role="button" href="#mainFooter" data-icon="arrow-d" data-iconpos="left" class="headerbutton">Menu</a>
$(document).on("click", "#menu-button", function(event){
    $('html,body').animate({ scrollTop: $('#mainFooter').offset().top }, { duration: 'slow', easing: 'swing'});
});

这是围绕jquery mobile的功能设计而来的。使用答案@dSquared@AdamD:从jQuery1.7开始,.delegate()已被.on()方法取代。这是围绕jQueryMobile的功能设计的。使用答案@dSquared@AdamD:从jQuery1.7开始,.delegate()已被.on()方法取代。