动态添加< li />到< ul />在jQuery的移动 [英] Dynamically adding <li/> to <ul/> in jquery mobile

查看:102
本文介绍了动态添加< li />到< ul />在jQuery的移动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图将列表项添加到jquery mobile中的无序列表中,但格式似乎没有正确创建。

I'm trying to add list items to unordered lists in jquery mobile, but the formatting doesn't seem to be created properly.

<ul data-role="listview" data-theme="c" data-dividertheme="b">
                    <li data-role="list-divider">
                        Title Divider
                    </li>
                    <li>
                        <a href="test.html" data-transition="slide">List item 1</a>
                    </li>

 </ul>

脚本:

$('ul').append('<li><a>hello</a></li>');

由于某种原因,动态生成的li与静态创建的li的显示方式不同。有人知道为什么以及如何让它变成一样吗?

For some reason the li generated dynamically doesn't display the same way as the one that's statically created. Does anyone know why and how I can make it the same?

推荐答案

试试这个:

Try this:

$('ul').append($('<li/>', {    //here appending `<li>`
    'data-role': "list-divider"
}).append($('<a/>', {    //here appending `<a>` into `<li>`
    'href': 'test.html',
    'data-transition': 'slide',
    'text': 'hello'
})));

$('ul').listview('refresh');

这篇关于动态添加&lt; li /&gt;到&lt; ul /&gt;在jQuery的移动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆