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>')