2014-07-25 83 views
1

Dr.Molle先前提出的問題see here給出的答案是正確的,但僅適用於<div>。我被迫使用<table>。我發現了另一個腳本,可以在我的VBScript之外完美工作,但不在裏面。Toggle table​​in .hta

我希望你們中的一些人能夠再次幫助我。這意味着很多。

將完整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> 
+0

沒有人對此有答案? :) – Sparcx

+0

這可能是因爲「它不工作」不是一個適當的錯誤描述。但是,請嘗試'

相關問題