0

我有一个滑动来为我在每个页面上运行的 ios Web 应用程序执行脚本,但我想知道如何排除影响显示的第一页。剧本是这样的

<script>
$(document).bind('swiperight', function () {
        history.back();
    });</script>

如何排除假设 id 为“home”的页面?

4

3 回答 3

2

我假设您使用的是 jQuery mobile(如果您不使用,请道歉),您可以使用 $.mobile.activePage 检查您是否在家:

http://jquerymobile.com/demos/1.2.0/docs/api/methods.html(在底部)

<script>
    $(document).bind('swiperight', function () {
        if ( $.mobile.activePage !== 'home' )
          history.back();
    });
</script>
于 2013-03-07T14:10:44.757 回答
1
$(document).bind('swiperight', function () {
    if (!$('body#home').length === 0) {
         history.back();
         // ... anything else
    }
});

你也可以使用:if (!$('#page.home').length === 0)如果它是一个包含元素的类,那么它if ($('#page').hasClass('home'))也是一种更可靠的 jQuery-y 方式。

于 2013-03-07T14:06:20.177 回答
1

一般原则是这样的:

<script>
var id = // get your hypothetical id from somewhere;
if(id !== "home") {
    $(document).bind('swiperight', function () {
        history.back();
    });
}
</script>

如果没有更多关于假设 id 来自何处的信息,很难比这更具体。

于 2013-03-07T14:06:47.507 回答