2011-06-14 3 views
1

다음 코드를 사용하여 동적으로 목록을 만듭니다. 그것은 잘 작동하지만 특정 목록 항목을 클릭하면 선택한 행의 글꼴 색이 노란색으로 바뀌어야합니다. 내가 어떻게 해?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"); 

     }); 

답변

2

이것은 오타입니다? $ ('#의 DateListView 리 ")는 단일 또는 이중 따옴표

일치해야이 :

$('#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 

는 UPDATE :

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

안녕하세요, 감사 필 ,, 나는 .. 노력하지만 오류 $ (이) .setAttribute이 정의되지 보여줍니다. 제발 나를 도와 – Finder

+0

대신 setAttribute 사용 attr, 내 업데이 트를 참조하십시오 –

관련 문제