zoukankan      html  css  js  c++  java
  • XML数据绑定到Table中

    简单的XML数据绑定例子:

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="zh-cn">
    <title>Binding xml data</title>
    <head>
    <script type="text/javascript" language="javascript">
    function init()
    {
    //初始化页面中的总页数
    var totPage = document.getElementById('total');
    totPage.innerText
    = data.recordset.recordcount;
    }

    function page(databox,datasrc,moveto)
    {
    /*
    函数参数: databox为容器的id,即此例中id为oTab的table datasrc为数据源id,
    即此例中的data moveto为翻页方式:firstPage(首页)|previousPage(上页)|nextPage(下页)|lastPage(末页)
    */
    var curPage=document.getElementById('current');
    switch (moveto)
    {
    case 'firstPage':
    databox.firstPage();datasrc.recordset.movefirst();
    break;
    case 'lastPage':
    databox.lastPage();datasrc.recordset.movelast();
    break;
    case 'previousPage':
    if (datasrc.recordset.absoluteposition > 1)
    {
    databox.previousPage();
    datasrc.recordset.moveprevious();
    }
    break;
    case 'nextPage':
    if (datasrc.recordset.absoluteposition < datasrc.recordset.recordcount)
    {
    databox.nextPage();
    datasrc.recordset.movenext();
    }
    break;
    }
    curPage.innerText
    =datasrc.recordset.absoluteposition;//显示当前页数
    }
    </script>

    </head>

    <body onload="init();">
    <!--内部数据源实例-->
    <!-- 如内容较多时可单独存放在test.xml文件中,然后用<xml src="test.xml"></xml>导入 -->
    <!--<xml id="data" src="test.xml""></xml><-->

    <xml id="data">
    <root>
    <article>
    <title>第一页</title>
    <content>1111111111111111</content>
    </article>
    <article>
    <title>第二页</title>
    <content>2222222222222222</content>
    </article>
    <article>
    <title>第三页</title>
    <content>3333333333333333</content>
    </article>
    <article>
    <title>第四页</title>
    <content>4444444444444444</content>
    </article>
    <article>
    <title>第五页</title>
    <content>55555555555</content>
    </article>
    </root>
    </xml>

    <table datasrc="#data" dataPageSize="1" id="oTab" border="1">
    <tr>
    <td>title:</td>
    <td><span datafld="title"/></td>
    </tr>
    <tr>
    <td>content:</td>
    <td valign="top"><span datafld="content" /></td>
    </tr>
    </table>
    <div>
    <input type="button" value="首 页" onclick="page(oTab,data,'firstPage');" />
    <input type="button" value="上 页" onclick="page(oTab,data,'previousPage');" />
    <input type="button" value="下 页" onclick="page(oTab,data,'nextPage');" />
    <input type="button" value="末 页" onclick="page(oTab,data,'lastPage');" />
    <br/><span id="current">1</span> 页 | 共 <span id="total"></span>&nbsp;&nbsp;
    </div>
    </body>
    </html>



  • 相关阅读:
    1040 最大公约数之和
    51nod 1215 数组的宽度
    51nod 1423 最大二“货” 单调栈
    51nod 1437 迈克步 单调栈
    1564 区间的价值
    51nod 1294 修改数组
    51nod1693 水群 最短路
    51nod1052 最大M子段和
    我不管,这就是水题《1》
    河工大校赛 Hmz 的女装 http://218.28.220.249:50015/JudgeOnline/problem.php?id=1265
  • 原文地址:https://www.cnblogs.com/wintergrass/p/2380121.html
Copyright © 2011-2022 走看看