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