0

我動態的網頁添加<li>checkBoxes我是usinh JQuery Mobile但添加它不能正常顯示後,我試着用$('#contactList').listview('refresh')但它顯示錯誤listview is not a function 這裏是我的HTML部分刷新列表視圖和複選框在jQuery Mobile的

<ul data-role="listview" data-inset="true" data-filter="true" data-filter-placeholder="Search" id="contactList"> 
       </ul> 

和JS部分,我動態地添加是

$('#contactList').append('<li>\ 
        <input type="checkbox" name="'+contactId+'" id="'+contactId+'" class="custom" />\ 
        <label for="checkbox-5a">\ 
         <span class="span2 contact-name">\ 
         '+contactName+'\ 
         </span>\ 
         <span class="contact-image">\ 
          <img src="'+contactImage+'"/>\ 
         </span>\ 
        </label>\ 
       </li>') 

現在我怎麼刷新都licheck boxes所以他們看起來正確

更新::我的頁標題是這樣的

<script src="js/jquery-1.9.1.min.js"></script>      <!-- Scripts n CSS --> 
<script src="js/jquery.mobile-1.3.1.min.js"></script>    <!-- for J Query Mobile --> 
<link rel="stylesheet" href="css/jquery-ui.css" /> 
<link rel="stylesheet" href="css/jquery.mobile-1.3.1.min.css" /> 


<script src="js/jquery-ui.js"></script> 

<!-- For BootStrap --> 

<link href="css/bootstrap.css" type="text/css" rel="stylesheet"/> 
<link href="css/bootstrap-responsive.css" type="text/css" rel="stylesheet"/><!-- Must Same Order --> 

<!-- HTML5 shim for IE backwards compatibility --> 
<!--[if lt IE 9]> 
    <script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script> 
<![endif]--> 

<!-- User Generated JS Files --> 
<script src="lib/work-space.js"></script> 
<script src="lib/contactsFile.js"></script> 
+0

這是你想要的嗎? http://jsfiddle.net/Palestinian/pBTrn/ – Omar

+0

是的,我想這個,我已經試過這個,但它顯示我錯誤 'TypeError:$(...)。append(...)。listview is not函數' – Blu

+0

我也更新我的問題,幷包括頁面的頭部分 – Blu

回答

0

你應該label-for使用相同的名稱checkbox

你的代碼是

$('#contactList').append('<li>\ 
       <input type="checkbox" name="'+contactId+'" id="'+contactId+'" class="custom" />\ 
       <label for="checkbox-5a">\ 
        <span class="span2 contact-name">\ 
        '+contactName+'\ 
        </span>\ 
        <span class="contact-image">\ 
         <img src="'+contactImage+'"/>\ 
        </span>\ 
       </label>\ 
      </li>') 

但你應該寫這個

$('#contactList').append('<li>\ 
       <input type="checkbox" name="'+contactId+'" id="'+contactId+'" class="custom" />\ 
       <label for="'+contactId+'">\ 
        <span class="span2 contact-name">\ 
        '+contactName+'\ 
        </span>\ 
        <span class="contact-image">\ 
         <img src="'+contactImage+'"/>\ 
        </span>\ 
       </label>\ 
      </li>')