2012-05-03 5 views
1

JQuery Mobile 앱이 있습니다. 이 앱에는 '선택'요소가 포함 된 페이지가 있습니다. 요소의 옵션을 동적으로 추가해야합니다. 내 삶을 위해서, 나는 이것을하는 법을 알 수 없다. 현재, 나는 다음과 같은 노력하고있어 :JQuery Mobile에서 선택 목록을 동적으로 채 웁니다.

page.html

<div id="myPage" data-role="page"> 
    <div data-role="header" data-position="fixed"> 
    <h1>Welcome</h1> 
    </div> 

    <div data-role="content"> 
    <select name="mySelector" id="mySelector" data-native-menu="false"> 
     <option>Please Choose</option>     
    </select> 
    </div> 
</div> 

page.html.js

어떤 이유
$("#myPage").live("pagebeforeshow", function (e, ui) { 
    for (i=0; i<5; i++) { 
    $("#mySelector", "#myPage").append('<option value="' + i + '">Option ' + (i+1) + '</option>'); 
    } 
}); 

, 내 동적 항목이 표시되지 않습니다. 내가 도대체 ​​뭘 잘못하고있는 겁니까?

+0

,하지만 당신은'$를 쓰지한다 , "#myPage")'? – sp00m

답변

2

당신은 호출해야합니다 : 대신`$ ("#의 mySelector"의 '("#의 mySelector") 어쩌면 내가 틀렸다

$('#mySelector').selectmenu('refresh'); 
관련 문제