在.hta中切换表格

时间:2014-07-25 14:51:04

标签: javascript html vbscript html-table show-hide

Dr.Molle在早期问题see here中给出的答案是正确的,但仅适用于<div>。我被迫使用<table>。我找到了另一个在我的VBScript之外完美运行的脚本,但不在内部。

我希望你们中的一些人可以再次帮助我。这意味着很多。

当将Full HTA中的代码放入HTA文件并将数据库附加到其中时,纯HTML中的脚本(以HTML格式测试)正在运行,但VBScript中的脚本不起作用。我怎样才能使这个内部工作?

的Javascript

<script>
$(document).ready(function() {
      $('table.detail').each(function() {
        var $table = $(this);
        $table.find('.parent').click(function() {
            $(this).nextUntil('.parent').toggle(); // must use jQuery 1.4 for nextUntil() method
        });

        var $childRows = $table.find('tbody tr').not('.parent').hide();
        $table.find('button.hide').click(function() {
            $childRows.hide();
        });
        $table.find('button.show').click(function() {
            $childRows.show();
        });
    });
});
</script>

完整HTA

<html>
<HTA:APPLICATION ID="oHTA"
     APPLICATIONNAME="myApp"
     BORDER="thick"

     CAPTION="yes"
     ICON=./images/Icon.ico
     MAXIMIZEBUTTON="yes"
     MINIMIZEBUTTON="yes"
     SHOWINTASKBAR="yes"
     SINGLEINSTANCE="no"
     SYSMENU="yes"
     RESIZE="yes"
     VERSION=7.2
     WINDOWSTATE="normal"
     contextMenu=no
  >
<head>
<script type="text/javascript"> // Width and height in pixel to the window
    window.resizeTo(683,725);
</script>

<title>Søgning</title>
<link href="stylesheet/stylesheet.css" rel="stylesheet" type="text/css" />
<link rel="SHORTCUT ICON" href="images/icon.ico"/>
<script type="text/javascript" charset="utf-8" src="jquery/jquery-1.7.min.js"></script>
<script>
$(document).ready(function() {
      $('table.detail').each(function() {
        var $table = $(this);
        $table.find('.parent').click(function() {
            $(this).nextUntil('.parent').toggle(); // must use jQuery 1.4 for nextUntil() method
        });

        var $childRows = $table.find('tbody tr').not('.parent').hide();
        $table.find('button.hide').click(function() {
            $childRows.hide();
        });
        $table.find('button.show').click(function() {
            $childRows.show();
        });
    });
});
</script>

<script language="vbscript">

Dim conn 'GLOBAL doing this here so that all functions can use it
sub dotheconnection
    Set conn = CreateObject("ADODB.Connection")
    conn.Open "Provider=Microsoft.Jet.OLEDB.4.0; Data Source =./Database/data.mdb; User Id=; Password="
    If conn.errors.count <> 0 Then 
    else
        ' if connected OK call sub getdata
        getdata
    end if
end sub

sub getdata

    SQL_query = "SELECT * FROM dvd ORDER BY Title"
    Set rsData = conn.Execute(SQL_query)

    strHTML = strHTML & "<table class='detail' border=1 width='97%'><col style='width: 40px;'><col style='width: 80px;'><col style='width: 150px;'><col style='width: 40px;'><thead><tr><th colspan='4' align='left'><button class='show'>Show all</button><button class='hide'>Hide all</button></th></tr></thead>"
    Do Until rsData.EOF = True
    strHTML = strHTML & "<tbody><tr class='parent' style='font-weight: bold;'><td colspan='3'>" & rsData("Title") & "</td><td>" & rsData("Cat") & "</td></tr><tr><td colspan='4'>" & rsData("Notes") & "</td></tr></tbody>"

    rsData.moveNext ' go to next record
    Loop

    strHTML = strHTML & "</table>"

    SQL_query = "SELECT Count(*) AS intTotal FROM dvd"
    Set rsData = conn.Execute(SQL_query)
    strHTML1 = strHTML1 & ""
    strHTML1 = strHTML1 & "" & rsData("intTotal") & " "
    Count.innerHTML = strHTML1
end sub

sub searchdata

    SQL_query = "SELECT * FROM dvd WHERE Title LIKE '%"& txtsrch.value &"%' OR Notes LIKE '%"& txtsrch.value &"%' ORDER BY Title"
    Set rsData = conn.Execute(SQL_query)
    strHTML2 = strHTML2 & "<table class='detail' border=1 width='97%'><col style='width: 40px;'><col style='width: 80px;'><col style='width: 150px;'><col style='width: 40px;'><thead><tr><th colspan='4' align='left'><button class='show'>Vis alle</button><button class='hide'>Skjul alle</button></th></tr></thead>"
    Do Until rsData.EOF = True
    strHTML2 = strHTML2 & "<tbody><tr class='parent' style='font-weight: bold;'><td colspan='3'>" & rsData("Title") & "</td><td>" & rsData("Cat") & "</td></tr><tr><td colspan='4'>" & rsData("Notes") & "</td></tr></tbody>"
    rsData.moveNext ' go to next record
    Loop
    strHTML2 = strHTML2 & "</table>"
    searchIT.innerHTML = strHTML2

end sub

sub deleteUser(id)
    If MsgBox("Vil du slettet dette notat?", vbYesNo) =vbYes Then       
    SQL_query = "DELETE * FROM dvd WHERE ID = " & id
    conn.Execute(SQL_query)
    getdata
    reloadpage()
Else
    MsgBox("Notatet er ikke blevet slettet.")
End IF
end sub

sub addUser

    SQL_query = "INSERT INTO dvd (Title,Length,Notes,Cat) VALUES ('"& txtTitle.value &"','"& txtLength.value &"','"& txtNotes.value &"','"& txtCat.value &"')"
    conn.Execute(SQL_query)
    reloadpage()
    expandcontent("sc2")
    getdata

end sub

sub editUser(id)

    SQL_query = "SELECT * FROM dvd WHERE ID=" & id
    Set rsData=conn.Execute(SQL_query)
    txtTitle.value = rsData("Title")
    txtLength.value =   rsData("Length")
    txtNotes.value =    rsData("Notes")
    txtCat.value =  rsData("Cat")
    txtID.value = rsData("ID")
    btnUpdate.disabled = false // Show
    btnOpret.disabled = true // Hide
    expandcontent("sc2")
    getdata

end sub


sub updateUser

    SQL_query = "UPDATE dvd SET Title='"& txtTitle.value &"', Length='"& txtLength.value &"' , Notes='"& txtNotes.value &"', Cat='"& txtCat.value &"' WHERE ID= " & txtID.value 
    conn.Execute(SQL_query)
    getdata
    reloadpage()
    expandcontent("sc2")

end sub


</script>
<SCRIPT TYPE="text/javascript">
function init()
{
dotheconnection();
searchdata();
getdata();
}
</SCRIPT>
    <script>
function addNotat() {
    btnOpret.disabled = false; // Show
    btnUpdate.disabled = true; // Hide
    expandcontent("sc2");
}
</script>
</head>

<body onLoad="init()" language="vbscript">
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td height="40" width="20%" id="top_bar">
<input language="vbscript" onload="searchdata" onkeyup="searchdata" name="txtsrch" id="filter_input" width="15%" tabindex="0" autofocus="autofocus" size="35" type="search" style="background: url(images/search_bg.png) #FFF no-repeat left; padding-left: 20px; margin-left: 10px" placeholder="Søgning">&nbsp;</td>

<td id="top_bar"></div><span id="Count"></span> notater </td>

<td width="22%" id="top_bar" align="right"><input type="button" style="margin-right: 10px" onClick="history.go(0)" value="Opdater"><a onClick="addNotat()" style="cursor: hand">Opret</a>&nbsp;</span></td>
<td width="20%" id="top_bar" align="right"><a href="" target="_blank"><img src="images/footer-logo.png" style="margin-right: 10px" border="0" title="Gå til forsiden" /></a></td>
</tr>
</table>
<br>
<div id="searchIT" style="margin-left: 10px"></div><br><br><b>Testing in HTML</b>
<table class='detail' border=1 width='97%'><col style='width: 40px;'><col style='width: 80px;'><col style='width: 150px;'><col style='width: 40px;'><thead><tr><th colspan='4' align='left'><button class='show'>Show all</button><button class='hide'>Hide all</button></th></tr></thead><tbody><tr class='parent' style='font-weight: bold;'><td colspan='3'>Title</td><td>Categori</td></tr><tr><td colspan='4'>Note description</td></tr></tbody></table>
</body>
</script>

</html>

1 个答案:

答案 0 :(得分:0)

自己找到解决方案。

通过使用$(window).load(function () {,脚本被识别出来。完整的脚本:

<script type="text/javascript">
$(window).load(function () {
      $('table.detail').each(function() {
        var $table = $(this);
        $table.find('.parent').click(function() {
            $(this).nextUntil('.parent').toggle(); // must use jQuery 1.4 for nextUntil() method
        });
        var $childRows = $table.find('tbody tr').not('.parent').hide();
        $table.find('button.hide').click(function() {
            $childRows.hide();
        });
        $table.find('button.show').click(function() {
            $childRows.show();
        });
    });
});
</script>