javascript - jQuery Mobile ListView 按钮不可见

标签 javascript jquery listview jquery-mobile

我已直接在 HTML 文件中对 Div 内的 jQuery Mobile 按钮进行硬编码,并且它显示正确。请找到下面的图片

enter image description here

但是当我通过 JavaScript 修改它时,这两个按钮消失了。不知道为什么。请找到下面的图片

enter image description here

难道是因为 jQuery Mobile Listview 动态删除了一些样式吗?

这是 HTML

<div data-role="content" data-theme="c">    
<div id="ListOfCals">
<ul data-role="listview">
<li data-icon='false'>
<div id='ColorCodeDiv' style='background-color:#FFF;'></div>
Calendar 2
<p style='margin-top:2px'><strong><font size='2' color='#006600'>Active</font></strong></p>
<div id='calendarListView'>
<a name='del' data-role='button' href='#' data-icon='delete' data-theme='g' data-iconpos='notext' data-inline='true' data-bttype='delete'></a>
<a name='del' data-role='button' href='#' data-icon='gear' data-theme='e' data-iconpos='notext' data-inline='true' data-bttype='edit'></a>
</div>
</li>
</ul>
</div>

这是使用的 JavaScript 代码

var strCalList = "<ul data-role='listview'>";
var ListOfCals = JSON.parse(data.d);
$(ListOfCals).each(function(){

strCalList +="<li data-icon='false'>";
strCalList += "<div id='ColorCodeDiv' style='background-color:"+$.trim(this.ColorCode)+"'></div>"
strCalList += this.CalendarName;
if(this.Active==true){
strCalList +="<p style='margin-top:2px'><strong><font size='2' color='#006600'>Active</font></strong></p>" ;
}
else if(this.Active==false){
strCalList +="<p style='margin-top:2px'><strong><font size='2' color='#FF0000'>Inactive</font></strong></p>";
}

strCalList +="<div id='dvBtn'>";
strCalList += "<a name='del' data-role='button' href='#' data-icon='gear' data-theme='e' data-iconpos='notext' data-inline='true' data-bttype='edit' ></a>";
strCalList +="<a name='del' data-role='button' href='#' data-icon='delete' data-theme='g' data-iconpos='notext' data-inline='true' data-bttype='delete'></a>";

strCalList +="</div>";
strCalList +="</li>";

});

strCalList = strCalList+"</ul>";
$('#ListOfCals').html(strCalList);
$('#ListOfCals ul').listview();

有人能弄清楚为什么吗?感谢您提前抽出时间。

最佳答案

我刚刚尝试了您的示例,对我来说,使用 Windows 7 和 Firefox Nightly 可以正常工作,请参阅 here 。您是否仅在特定配置上遇到问题?

enter image description here

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>Test</title>
  <link rel="stylesheet" href="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.css" />
  <script src="http://code.jquery.com/jquery-1.8.2.min.js"></script>
  <script src="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.js"></script>
</head>

<body>
  <div data-role="page">
    <div data-role="content" data-theme="c">
      <div id="ListOfCals">
        <ul data-role="listview">
          <li data-icon='false'>
            <div id='ColorCodeDiv' style='background-color:#FFF;'></div>
            Calendar 2
            <p style='margin-top:2px'><strong><font size='2' color='#006600'>Active</font></strong></p>
            <div id='calendarListView'>
              <a name='del' data-role='button' href='#' data-icon='delete' data-theme='g' data-iconpos='notext' data-inline='true' data-bttype='delete'></a>
              <a name='del' data-role='button' href='#' data-icon='gear' data-theme='e' data-iconpos='notext' data-inline='true' data-bttype='edit'></a>
            </div>
          </li>
       </ul>
     </div>

     <script>
     $(document).on("mobileinit", function(){
       var strCalList = "<ul data-role='listview'>";
       var ListOfCals = JSON.parse(data.d);
       $(ListOfCals).each(function(){

         strCalList +="<li data-icon='false'>";
         strCalList += "<div id='ColorCodeDiv' style='background-color:"+$.trim(this.ColorCode)+"'></div>"
         strCalList += this.CalendarName;
         if(this.Active==true){
         strCalList +="<p style='margin-top:2px'><strong><font size='2' color='#006600'>Active</font></strong></p>" ;
         }
         else if(this.Active==false){
           strCalList +="<p style='margin-top:2px'><strong><font size='2' color='#FF0000'>Inactive</font></strong></p>";
         }

         strCalList +="<div id='dvBtn'>";
         strCalList += "<a name='del' data-role='button' href='#' data-icon='gear' data-theme='e' data-iconpos='notext' data-inline='true' data-bttype='edit' ></a>";
         strCalList +="<a name='del' data-role='button' href='#' data-icon='delete' data-theme='g' data-iconpos='notext' data-inline='true' data-bttype='delete'></a>";

         strCalList +="</div>";
         strCalList +="</li>";
       });

       strCalList = strCalList+"</ul>";
       $('#ListOfCals').html(strCalList);
       $('#ListOfCals ul').listview();
     });
     </script>
  </div>
</body>
</html>

关于javascript - jQuery Mobile ListView 按钮不可见,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13680861/

相关文章:

android - ListView 中的动态表单

wpf - 有没有一种简单的方法可以让 ListView 自动滚动到最近添加的项目,而无需在后面的代码中编写任何代码?

c - UWP - 刷新 ListView 和 CollectionViewSource

javascript - 如何抑制 `This document is trying to print. Do you want to allow this?`

jquery - 在窗口之间使用不同的本地存储

javascript - 将 CSS 和 JavaScript 放在文件或主 HTML 中?

javascript - 如何在不刷新整个页面的情况下刷新div?

javascript - 位置固定和宽度 100% 元素覆盖 IE 中的垂直滚动条

javascript - 如何获取通过 servlet 中的 jquery 添加的动态填充列表的值

javascript - 自定义文件选择器字段标签中的按钮