Mobile不会在页面init事件中的ListView元素上加载脚本

时间:2014-02-28 21:43:36

标签: jquery jquery-mobile

脚本在html文件加载时加载一次所以当我在pageinit或pagecreate上使用事件并在事件listview元素中写入带有文本数据的json时,应用程序编写html代码而没有任何脚本或样式的jquery mobile < / p>

<div data-role="page" id="hteacher" >  
<div data-role="header" data-position="fixed">
<h1>Welcome teacher 1</h1>
 <div data-role="navbar">
  <ul>

<div data-role="page" id="hteacher" >  
<div data-role="header" data-position="fixed">
<h1>Welcome teacher 1</h1>
 <div data-role="navbar">
  <ul>
    <li><a href="#hteacher" data-icon="home">Home</a></li>
    <li><a href="#t_addclass" data-icon="plus" data-rel="dialog">ADD Class</a></li>
    <li><a href="#msg_page" data-icon="star" data-rel="dialog">MSG</a></li>
  </ul>
  </div>
  </div>

 <div data-role="content">
 <p></p>
 <h2>list of classes </h2>
 <ul data-role="listview" id="classes_list" data-autodividers="true" data-inset="true"        data-filter="true">
 <script>
$( document ).delegate("#hteacher", "pagecreate", function() {
   var  html =  ' <li><a href="#"><img src="student1.jpg">BESHOY</a></li>';
   html +=  ' <li><a href="#"><img src="student2.jpg">MARY</a></li>';
  $("#classes_list").append (html );
          });

   </script>
   </ul>
  </div>

   <div data-role="footer" data-position="fixed">
   <h1>Welcome To .....</h1>
  </div>

  </div>    `

1 个答案:

答案 0 :(得分:0)

试试这个。

在你的HTML中:

<div data-role="page" id="indexpage">
<div data-role="header" data-position="fixed">

<h1>Welcome teacher 1</h1>

    <div data-role="navbar">
        <ul>
            <li><a href="#hteacher" data-icon="home">Home</a>
            </li>
            <li><a href="#t_addclass" data-icon="plus" data-rel="dialog">ADD Class</a>
            </li>
            <li><a href="#msg_page" data-icon="star" data-rel="dialog">MSG</a>
            </li>
        </ul>
    </div>
</div>
<div data-role="content">
    <p></p>
     <h2>list of classes </h2>

    <ul data-role="listview" id="classes_list" data-autodividers="true" data-inset="true" data-filter="true"></ul>
</div>
<div data-role="footer" data-position="fixed">
     <h1>Welcome To .....</h1>

</div>
</div>`

和脚本是:

$(document).on("pagecreate", "#indexpage", function () {
var  text =  '<li><a href="#">BESHOY</a></li>';
text +=  ' <li><a href="#">MARY</a></li>';
$("#classes_list").append (text );

});

将这个小提琴称为输出Demo

相关问题