2012-05-25 99 views

回答

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

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

關於data()

0

所以,使用jQuery手機,如果您通過ajax調用生成鏈接,則始終存在問題。這是因爲在初始化時,jQuery手機往往會改變很多關於元素的事情。因爲,如果你正在做一個像我這樣的項目,你可能會有很多地方想要彈出窗口,從而使應用程序變得很慢,所以我不能繼續生成多個彈出窗口。因此,每次有人點擊鏈接時,我們只會彈出一個彈出窗口並更改內容。

我創建了一個小提琴看你的問題。給它一個鏡頭,歡呼聲

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(''); 
});