0

当我动态创建一个带有列表视图的弹出窗口时,我在列表视图中获得了额外的(静态)项目。这是jsBin上显示问题的代码。

为什么li列表中有两个额外的?

只是在这里也有代码:

$_coursemenu = function( params ) {
  if ( window === this )
    return new $_coursemenu( params );
  var self = this;
  this.params = params;
  this.init();
};

$_coursemenu.prototype = {
  init: function() {
    this.page = $('<div id="' + this.params.id + '" data-theme="a" data-role="popup" data-history="false"  data-position-to="window"></div>').appendTo( this.params.parent );
    this.ul = $('<ul data-role="listview" data-inset="true" data-theme="b" data-autodividers="false"></ul>').appendTo( this.page );
    this.lid = $('<li data-role="divider" data-theme="a">Popup API</li>').appendTo( this.ul );
    this.li1 = $('<li><a>delete</a><li>').appendTo( this.ul );
    this.li2 = $('<li><a>aha</a><li>').appendTo( this.ul );

    this.page.popup();
    this.params.parent.page('destroy').page();

  },
  relocate: function(parent) {
    parent.append( $('#' + this.params.id + '-popup') );
    parent.append( $('#' + this.params.id + '-screen') );
  }

};

html:

<!DOCTYPE html>
<html>
  <head>
    <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 id='page' data-role='page'>
      <div data-role='content'>
        <a href='#mypopup' data-role='button' data-rel='popup'>popup</a>
      </div>
    </div>
    <script>
      $(document).ready( function(){
        var cm = $_coursemenu({parent:$('#page'),id:'mypopup'})
            console.log('done.');
      });
    </script>
  </body>
</html>
4

1 回答 1

1

你的问题是你没有关闭你的li标签,

$_coursemenu.prototype = {
  init: function() {
    this.page = $('<div id="' + this.params.id + '" data-theme="a" data-role="popup" data-history="false"  data-position-to="window"></div>').appendTo( this.params.parent );
    this.ul = $('<ul data-role="listview" data-inset="true" data-theme="b" data-autodividers="false"></ul>').appendTo( this.page );
    this.lid = $('<li data-role="divider" data-theme="a">Popup API</li>').appendTo( this.ul );
    this.li1 = $('<li><a>delete</a></li>').appendTo( this.ul );
    this.li2 = $('<li><a>aha</a></li>').appendTo( this.ul );
    this.page.popup();
    this.params.parent.page('destroy').page();

},

这是您的jsbin的更新

于 2012-12-10T14:55:02.057 回答