Jquerymobile ListView

时间:2011-06-14 14:58:49

标签: javascript jquery jquery-mobile

我正在使用以下代码动态创建列表。它工作正常但是当我单击特定列表项时,所选行的字体颜色应该变为黄色。我该怎么办?

提前致谢。

$('#DateListView').children().remove('li');

        //Make a new list
        var parent = document.getElementById('DateListView');

        for (var menuid = 0; menuid < weekStartDates.length; menuid++) {
            var listItem = document.createElement('li');
            listItem.setAttribute('id', 'listitem_' + weekStartDates[menuid]);
            listItem.innerHTML = "<div data-role='button' style='margin-left:10px;font-size:15px'data-theme ='c'  id='" + menuId + "'>" + Hai +"</div>";

            parent.appendChild(listItem);
        }
        var list = document.getElementById('DateListView');
        $(list).listview("refresh");
        $('#DateListView li ").bind("click", function() {
            $(this).setAttribute("style" , "font-color:yellow");

       });

1 个答案:

答案 0 :(得分:2)

这是一个错字吗? $('#DateListView li“)应该有匹配的单引号或双引号

此:

$('#DateListView li ").bind("click", function() {
    $(this).setAttribute("style" , "font-color:yellow");
});

应该是:

$('#DateListView li').bind("click", function() {
    $(this).setAttribute("style" , "font-color:yellow");
});

或:

$("#DateListView li").bind("click", function() {
    $(this).setAttribute("style" , "font-color:yellow");
});

此外,您可能希望在添加标记后调用刷新

$("#DateListView li").bind("click", function() {
    $(this).setAttribute("style" , "font-color:yellow");
});
$(list).listview("refresh"); // Move after added markup

更新:

 $("#DateListView li").bind("click", function() {
    $(this).attr("style" , "font-color:yellow");
});
$(list).listview("refresh"); // Move after added markup
相关问题