在渲染发生后以编程方式应用jquery(移动)css类

jquery mobile将根据页面加载时的数据属性自动为页面上的元素应用css和一些html。

我通过ajax调用拉入一些html内容,但是在jquery mobile js呈现之后它被引入页面,因此没有获得许多css类。

是否可以只调用js并要求渲染应用于我的新html内容?

之前

 

  

.page()到您的AJAX调用

例:

 var parm = '123'; function loadPage(page){ $.ajax({ url: 'page.php?parm='+value, type: 'POST', error : function (){ document.title='error'; }, success: function (data) { $('#placeholder').html(data).page(); } }); // Scrolls to the top of the page $.mobile.silentScroll(0); } 

HTML

 

在浏览了jquery.mobile-1.0a4.1.js并阅读这篇解释小部件用法的精彩文章后 ,答案很简单:

现有的mobile.listview小部件将渲染应用于listviews。

 $.widget( "mobile.listview", $.mobile.widget, { }); 

直接将其应用于html。 定位ul非常重要。

 $("div#someDiv ul").listview(); 

这是完整的例子

 function hijack(form) { $("div#someDiv").html(""); $("div#someDiv").addClass('loading'); $.ajax({ url: form.action, type: form.method, dataType: "html", data: $(form).serialize(), success: function(data) { $("div#someDiv").removeClass('loading'); $("div#someDiv").html(data); //apply rendering of jquery mobile styles via listview widget $("div#someDiv ul").listview(); } }); } 

.live()(http://api.jquery.com/live/)事件活页夹可能就是您要找的东西。