jquerymobile中div的局部刷新

  在jquerymobile中listview及表单的元素都有提供了动态添加元素之后进行刷新的方法,但div却没有,经过不断的实验之后,终于摸索出来解决办法。就是不能用模板的方法来动态添加元素,要用拼接字符串的方式来添加动态元素的内容,并且最后通过.trigger("create")事件来触发刷新。 举例作法:

不行的作法:

  var $moduleTemplate = $('<div data-role="collapsible"  data-collapsed="true">'
     +'<h3 class="h3Class">测试</h3>'
     +'<p>I am the collapsible content in a set so this feels like an accordion attribute.</p>'
     +'</div>');

  $('#moduleList').append($moduleTemplate.html()).trigger("create"); 这种模板的方法对于listview 表单元素进行动态添加是没问题的,但对于div却不行。

div要这样来作:

  $('#moduleList').append('<div data-role="collapsible"  data-collapsed="true">'
     +'<h3 class="h3Class">测试</h3>'
     +'<p>I am the collapsible content in a set so this feels like an accordion attribute.</p>'
     +'</div>').trigger("create");

 

  

 

 

 

posted on 2012-06-17 00:55  尔丘仁  阅读(2261)  评论(0编辑  收藏  举报