在更改事件之前确定 jQuery Mobile 页面的调用者

2024-01-18

我认为这是同一个问题JQM pagebeforechange 和事件源 https://stackoverflow.com/questions/9179096/jqm-pagebeforechange-and-event-source,但那里没有确凿的答案。

有谁知道如何获取触发事件的对象?

$(document).bind("pagebeforechange", function ( event , data) {
    //event is triggered from an anchor tag... 
    //Is it possible to get reference to anchor here?
});

Thanks.

更完整的例子:

<div data-role="page" id="ANGRY">
<div data-role="header">
    Solo Questions</div>
<div data-role="content">
    <fieldset data-role="controlgroup">
        <legend>Since your last scheduled prompt, how <strong>angry</strong> have you felt?</legend>
        <input type="radio" name="ANGRY" value="1" id="ANGRY1" />
        <label for="ANGRY1">
            None</label>
        <input type="radio" name="ANGRY" value="2" id="ANGRY2" />
        <label for="ANGRY2">
            Some</label>
        <input type="radio" name="ANGRY" value="3" id="ANGRY3" />
        <label for="ANGRY3">
            A Lot</label>
    </fieldset>
</div>
<div class="ui-grid-a">
    <div class="ui-block-a">
        <a href="#HAPPY" data-role="button" data-icon="arrow-l" data-iconpos="left">prev</a></div>
    <div class="ui-block-b">
        <a href="#IRRITABL" data-role="button" data-icon="arrow-r" data-iconpos="right">next</a></div>
</div>
</div>

我希望能够确定是什么触发了 pagebeforechange 事件 - “上一个”按钮或“下一个”按钮。这样做的目的是在移至下一页之前执行验证,但在返回上一页时不执行验证。


toPage 是否适用于此?

  • http://jsfiddle.net/pK6GX/1/ http://jsfiddle.net/pK6GX/1/

JS

$(document).bind("pagebeforechange", function ( event , data) {
    console.log('To Page: '+data.toPage);
});​

HTML

<div data-role="page" id="home">
    <p>Open up the console and Click the Info link</p>
    <ul>
        <li><a href="#info">Info</a></li>
    </ul>
</div>

<div data-role="page" id="info">
    <ul>
        <li><a href="#home">Home</a></li>
    </ul>
</div>​
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

在更改事件之前确定 jQuery Mobile 页面的调用者 的相关文章

随机推荐