📄 sort1.htm
字号:
<HTML>
<Head>
<META http=equiv="Content-Type" Content="text/html;charset=gb2312"/>
<STYLE>
body { font-family:宋体; font-size:9pt;}
th { font-family:宋体; font-size:9pt; font-weight:bold;}
</STYLE>
<Script language="vbscript">
Option Explicit
Dim intRecordsPerPage '每个页面显示的记录数
intRecordsPerPage = 8 '每个页面显示的记录数,默认设定为6
Function window_onload() ' 更新显示页面的函数
' 显示设定的记录数
'Style.XMLDocument.selectNodes("//xsl:for-each/@select")(1).Value = "./*[position() < " & intRecordsPerPage + 1 & " and position() > 0]"
Style.XMLDocument.selectSingleNode("//table[@id='table2']/xsl:for-each/@select").Value = "./*[position() < " & intRecordsPerPage + 1 & " and position() > 0]"
transform()
setFirstPageCount()
'=============================================================================
DisplayTest.innerHTML = Data.XMLDocument.selectSingleNode("/*/*[0]").nodename
'=============================================================================
End Function
Function transform() ' 进行XML-XSLT转换,并显示当前记录的一些信息
DisplayArea.innerHTML =Data.transformNode(Style.DocumentElement)
RecordsPerPage.Value = intRecordsPerPage
End Function
Function setFirstPageCount() ' 显示页数信息
Dim intTotalRecords
PageCount.innerHTML = getNumberOfPages(intTotalRecords)
RecordCount.innerHTML = intTotalRecords
CurrentPage.innerHTML = 1
End Function
Function Sort(strField) ' 重新排序和显示
Dim sortField
Dim sortOrderAttribute
' 得到排序属性值
Set sortField = Style.XMLDocument.selectSingleNode("//table[@id='table2']/xsl:for-each/xsl:sort/@select")
Set sortOrderAttribute = Style.XMLDocument.selectSingleNode("//table[@id='table2']/xsl:for-each/xsl:sort/@order")
' 改变排序的方式
If sortField.Value = strField Then 'Or sortField.Value = "./*[0]" Then
If sortOrderAttribute.Value = "descending" Then
sortOrderAttribute.Value = "ascending"
Else
sortOrderAttribute.Value = "descending"
End If
Else
sortField.Value = strField
sortOrderAttribute.Value = "ascending"
End If
Set sortField = Nothing
Set sortOrderAttribute = Nothing
redisplay (CurrentPage.innerHTML)
End Function
Function redisplay(intPage) ' 重新转换XML,并显示一个状态信息
Dim strDisplay
Dim intPageCount
Dim intRecordCount
' 保存状态信息
intPageCount = PageCount.innerHTML
intRecordCount = RecordCount.innerHTML
transform()
' 显示状态信息
PageCount.innerHTML = intPageCount
RecordCount.innerHTML = intRecordCount
CurrentPage.innerHTML = intPage
End Function
Function nextPage(intPage) ' “下一页”的处理
Dim strDisplay
Dim strDateRange
If CInt(CStr(intPage) * intRecordsPerPage) < Data.selectNodes("/*/*").length Then
intPage = CInt(intPage) + 1
Style.XMLDocument.selectSingleNode("//input[@id='previousPage']/@OnClick").Value = "previousPage(" & intPage & ")"
Style.XMLDocument.selectSingleNode("//input[@id='nextPage']/@OnClick").Value = "nextPage(" & intPage & ")"
Style.XMLDocument.selectSingleNode("//table[@id='table2']/xsl:for-each/@select").Value = "./*[position() <= " & (CStr(intPage) * intRecordsPerPage) & " and position() > " & (CInt(intPage) - 1) * intRecordsPerPage & "]"
redisplay (intPage)
End If
End Function
Function previousPage(intPage) ' 处理“上一页”
Dim strDisplay
Dim strDateRange
If intPage > 1 Then
intPage = CInt(intPage) - 1
Style.XMLDocument.selectSingleNode("//input[@id='previousPage']/@OnClick").Value = "previousPage(" & intPage & ")"
Style.XMLDocument.selectSingleNode("//input[@id='nextPage']/@OnClick").Value = "nextPage(" & intPage & ")"
Style.XMLDocument.selectSingleNode("//table[@id='table2']/xsl:for-each/@select").Value = "./*[position() <= " & (CStr(intPage) *intRecordsPerPage) & " and position() > " & (CInt(intPage) - 1) * intRecordsPerPage & "]"
redisplay (intPage)
End If
End Function
Function FirstPage() ' “第一页”的处理
Style.XMLDocument.selectSingleNode("//input[@id='previousPage']/@OnClick").Value = "previousPage(1)"
Style.XMLDocument.selectSingleNode("//input[@id='nextPage']//@OnClick").Value = "nextPage(1)"
Style.XMLDocument.selectSingleNode("//table[@id='table2']/xsl:for-each/@select").Value = "./*[position() < " & intRecordsPerPage + 1 & " and position() > 0]"
transform()
setFirstPageCount()
End Function
Function LastPage() ' “最末页”的处理
Dim intTotalPages
Dim intTotalRecords
intTotalPages = getNumberOfPages(intTotalRecords)
nextPage (intTotalPages - 1)
End Function
Function setRecordsPerPage() ' 重新设置每页的记录数
If IsNumeric(RecordsPerPage.Value) Then
intRecordsPerPage = CInt(RecordsPerPage.Value)
window_onload
End If
End Function
Function getNumberOfPages(intTotalRecords) ' 计算总页数和总记录数
Dim intPages
intTotalRecords = Data.XMLDocument.selectNodes("/*/*").length
intPages = intTotalRecords / intRecordsPerPage
If InStr(intPages, ".") > 0 Then
intPages = CInt(Left(intPages, InStr(intPages, "."))) + 1
End If
getNumberOfPages = intPages
End Function
</Script>
</Head>
<body>
<p align="center" style="font-weight:bold;font-size:12pt;color:#0000FF;border-bottom:3px double red;padding-bottom:5px">客户关系表</p>
<XML id='Data' src='sort1.xml'></XML>
<XML id='Style' src='sort1.xsl'></XML>
<div id="DisplayArea"></div>
<div id="DisplayTest"></div>
</body>
</HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -