简体   繁体   English

拨动表 <td> 在.hta

[英]Toggle table <td> in .hta

The answer given in an earlier question see here by Dr.Molle was correct, but only worked with <div> . 在前面的问题给出的答案在这里看到由Dr.Molle是正确的,但只工作<div> I am forced to use <table> . 我被迫使用<table> I have found a another script that works perfectly outside my VBScript, but not inside. 我发现另一个脚本可以在我的VBScript外部完美运行,但不能在内部完美运行。

I was hoping some of you could help me out again. 我希望你们中的一些人能再次帮助我。 It would mean a lot. 这很重要。

When the code from the Full HTA is put in to a HTA file and attach a database to it, the script (Testing in HTML) in plain HTML is working, but the one inside the VBScript is not. 当将完整HTA中的代码放入HTA文件并附加数据库时,纯HTML中的脚本(HTML中的测试)可以正常工作,而VBScript中的脚本则无效。 How can I make the one inside work as well? 我也该如何使内部工作呢?

Javascript 使用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>

Full HTA 完整的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>

Found the solution myself. 自己找到解决方案。

By using the $(window).load(function () { the script was recognized. Full script here: 通过使用$(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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM