0

popup()在jquery mobile中使用过

$("#id").popup();

我想在弹出窗口打开时向该“id”元素添加一些数据。如何?

4

3 回答 3

3

将此添加到您的 JavaScript:

$("#id").on('popupafteropen', function(){
    // do whatever here
    $(this).append("Add some HTML!");
    $(this).html("Or replace the HTML contents.");
});

查看弹出插件的事件:http: //jquerymobile.com/test/docs/pages/popup/events.html

于 2012-11-17T21:51:22.540 回答
0

因此,对于 jQuery mobile,如果您通过 ajax 调用生成链接,总是会出现问题。这是因为在初始化时,jQuery mobile 往往会改变很多关于元素的事情。

此外,您不能一直生成多个弹出窗口,因为如果您正在从事像我这样的项目,您可能有很多地方需要弹出窗口,从而使应用程序变慢。因此,每次有人点击链接时,我们只制作一个弹出窗口并更改内容。

我创建了一个小提琴看你的问题。试一试,加油

http://jsfiddle.net/tanwaniniranjan/0hzco633/3/

html:

<a href="#popupBasic" data-rel="popup" data-transition="flip" class="popupcontentchanger">Open Popup</a>

<div data-role="popup" id="popupBasic" data-overlay-theme="a">
    <a href="#" data-rel="back" data-role="button" data-theme="a" data-icon="delete" data-iconpos="notext" class="ui-btn-right">Close</a>
    <div id="changehere"> <!-- We will be changing content in this div -->

    </div>
</div>

jQuery:

//script to change content
$(document).on("click",".popupcontentchanger",function(event){
    var newhtml = $(this).html();
    $(document).on("popupafteropen", "#popupBasic", function (e) {
        $("#popupBasic #changehere").html(newhtml);
    });
});

//script to clear current html in the popup, on closing of popup so that every time it opens, it loads new content, without initially showing the old content. would have been better if jquery mobile added another method: popupbeforeopen :P
$(document).on("popupafterclose", "#popupBasic", function (e) {
    $("#popupBasic #changehere").html('');
});
于 2014-09-01T07:00:08.843 回答
0
$('#id').attr('data-some', 'some').popup();

或者

$('#id').data('some', 'some').popup();

关于数据()

于 2012-05-25T10:50:16.693 回答