jQuerymobile ListView

问题描述

| 我正在使用以下代码动态创建列表。效果很好,但是当我单击特定的列表项时,所选行的字体颜色应变为黄色。我该怎么做? 提前致谢。
$(\'#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\");

       });
    

解决方法

        这是错字吗? $(\'#DateListView li \“)应该具有匹配的单引号或双引号 这个:
$(\'#DateListView li \").bind(\"click\",function() {
    $(this).setAttribute(\"style\",\"font-color:yellow\");
});
应该:
$(\'#DateListView li\').bind(\"click\",\"font-color:yellow\");
});
要么:
$(\"#DateListView li\").bind(\"click\",\"font-color:yellow\");
});
另外,您可能想在添加标记后调用刷新
$(\"#DateListView li\").bind(\"click\",\"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
    

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...