我有一个使用这个树视图组件的网站:
http://www.obout.com/t2/ex_expand_levels.aspx
我需要展开树视图的所有节点。我没有按钮(也没有功能),只有树视图本身。(请在下面找到代码示例)
我已加载页面并能够将 JavaScript 发送到网站,但无法模拟单击“+”符号以展开节点。我有几个。
如果可能的话,我真的很想在 Delphi 中看到一个简单的示例代码。
我用来执行 Javascript 的 Delphi 代码如下:
我的表单有一个 WebBrowser、一个编辑和一个按钮:
uses MSHTML;
procedure TForm1.ButtonJSButtonClick(Sender: TObject);
{ Make browser exec JS }
var
Doc: IHTMLDocument2; // current HTML document
HTMLWindow: IHTMLWindow2; // parent window of current HTML document
JSFn: string; // stores JavaScipt function call
begin
// Get reference to current document
Doc := WebBrowser1.Document as IHTMLDocument2;
if not Assigned(Doc) then
Exit;
// Get parent window of current document
HTMLWindow := Doc.parentWindow;
if not Assigned(HTMLWindow) then
Exit;
// Run JavaScript
try
JSFn := Edit1.Text;
HTMLWindow.execScript(JSFn, 'JavaScript');
except
// handle exception in case JavaScript fails to run
ShowMessage('Error running JavaScript |'+Edit1.Text+'|');
end;
end;
提前致谢,
佐尔特
JavaScript:
<!-- ASP TreeView component http://www.obout.com -->
<LINK REL=stylesheet HREF="/_tree/treeStyle_Explorer/obout_treeview.css" >
<SCRIPT LANGUAGE="JavaScript">
<!--
var op2, ob_tb, ob_url, selected_node_id;
function ob_wk(os, url) {
var ot = os.parentNode.nextSibling.firstChild.nextSibling;
var lensrc = (os.src.length - 8);
var s = os.src.substr(lensrc, 8);
if (s == "inus.gif") {
ot.style.display = "none";
os.src = "/_tree/treeStyle_Explorer/plusik.gif";
}
if (s == "usik.gif") {
ot.style.display = "block";
os.src = "/_tree/treeStyle_Explorer/minus.gif";
if (url != "") {
var s = os.parentNode.nextSibling.firstChild.nextSibling.innerText;
if (s != "Loading ...") {
return;
}
ob_url = url;
ob_tb = os;
window.setTimeout("ob_tm()", 100);
}
}
}
function ob_tm() {
var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
xmlhttp.open("GET", ob_url, false);
xmlhttp.send("");
ob_tb.parentNode.nextSibling.firstChild.nextSibling.outerHTML = xmlhttp.responseText;
}
function ob_ft(e) {
if (e.tagName == "TABLE" && e.className == "ob_zz") {
if (typeof op2 != "undefined") {
op2.style.backgroundColor = "transparent";
op2.style.border = "0px solid #999999";
op2.style.margin = "1px";
}
e.style.backgroundColor = "#E6E6E6";
e.style.border = "0px solid #aaceeb";
e.style.margin = "0px";
op2 = e;
selected_node_id = e.children(0).children(0).children(1).id;
}
else {
ob_ft(e.parentNode);
}
}
function ob_os(e){
var os = e.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.children(0).children(0);
if (os != null) {
if ((typeof os != "undefined") && (os.tagName == "IMG")) {
var lensrc = (os.src.length - 8);
var s = os.src.substr(lensrc, 8);
if ((s == "inus.gif") || (s == "usik.gif")) {
e.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.children(0).children(0).click();
}
}
else {
ob_os(e.parentNode);
}
}}
//-->
</SCRIPT>
<!-- ASP TreeView component http://www.obout.com -->
<div id="divTree" name="divTree" style="background:;background-image: url('');overflow-X:auto; overflow-Y:auto; width:; height:;"><table cellspacing=0 cellpadding=0 border=0 style="display:block;"><tr><td width=1 class=ob_ic><img class=ob_ic src='/_tree/treeStyle_Explorer/minus.gif' onclick="ob_wk(this, '')"></td><td><table cellspacing=0 cellpadding=0 border=0 class=ob_zz><tr><td width=1 class=ob_ic><img width=16 class=ob_ic src='/_tree/xpGlobe.gif'></td><td id=a0 onclick='ob_ft(this)' class=ob_td>Root</td></tr></table><table cellspacing=0 cellpadding=0 border=0 style="display:block;"><tr><td width=1 class=ob_ic><img class=ob_ic src='/_tree/treeStyle_Explorer/plusik.gif' onclick="ob_wk(this, '')"></td><td><table cellspacing=0 cellpadding=0 border=0 class=ob_zz><tr><td width=1 class=ob_ic><img width=16 class=ob_ic src='/_tree/folder.gif'></td><td id=b1 onclick='ob_ft(this)' class=ob_td><SPAN onclick='ob_os(this)'>TREE</SPAN></td></tr></table><table cellspacing=0 cellpadding=0 border=0 style="display:none;"><tr><td width=1 class=ob_ic><img class=ob_ic src='/_tree/treeStyle_Explorer/plusik.gif' onclick="ob_wk(this, '')"></td><td><table cellspacing=0 cellpadding=0 border=0 class=ob_zz><tr><td width=1 class=ob_ic><img width=16 class=ob_ic src='/_tree/xpHome.gif'></td><td id=c1 onclick='ob_ft(this)' class=ob_td><SPAN onclick='ob_os(this)'>Site1</SPAN></td></tr></table><table cellspacing=0 cellpadding=0 border=0 style="display:none;"><tr><td width=1 class=ob_ic> </td><td><table cellspacing=0 cellpadding=0 border=0 class=ob_zz><tr><td width=1 class=ob_ic><img width=16 class=ob_ic src='/_tree/xpPanel.gif'></td><td id=d1 onclick='ob_ft(this)' class=ob_td><input type=checkbox name=sIteID value=1_DD32B129-527A-42FA-A0D0-FE3C0ED65BC5><STRONG>Site1>Unit1</STRONG><input type=hidden name=sup_ value={DD32B129-527A-42FA-A0D0-FE3C0ED65BC5}></td><td align=right></td></tr></table></td></tr></table></td></tr><tr><td width=1 class=ob_ic><img class=ob_ic src='/_tree/treeStyle_Explorer/plusik.gif' onclick="ob_wk(this, '')"></td><td><table cellspacing=0 cellpadding=0 border=0 class=ob_zz><tr><td width=1 class=ob_ic><img width=16 class=ob_ic src='/_tree/xpHome.gif'></td><td id=c2 onclick='ob_ft(this)' class=ob_td><SPAN onclick='ob_os(this)'>Site2</SPAN></td></tr></table><table cellspacing=0 cellpadding=0 border=0 style="display:none;"><tr><td width=1 class=ob_ic> </td><td><table cellspacing=0 cellpadding=0 border=0 class=ob_zz><tr><td width=1 class=ob_ic><img width=16 class=ob_ic src='/_tree/xpPanel.gif'></td><td id=d2 onclick='ob_ft(this)' class=ob_td><input type=checkbox name=sIteID value=2_E6DC2021-F8E9-4FBE-93F5-79C953FA7BA8><STRONG>Site2>Unit2</STRONG><input type=hidden name=sup_ value={E6DC2021-F8E9-4FBE-93F5-79C953FA7BA8}></td><td align=right></td></tr></table></td></tr></table></td></tr><tr><td width=1 class=ob_ic><img class=ob_ic src='/_tree/treeStyle_Explorer/plusik.gif' onclick="ob_wk(this, '')"></td><td><table cellspacing=0 cellpadding=0 border=0 class=ob_zz><tr><td width=1 class=ob_ic><img width=16 class=ob_ic src='/_tree/xpHome.gif'></td><td id=c3 onclick='ob_ft(this)' class=ob_td><SPAN onclick='ob_os(this)'>Site3</SPAN></td></tr></table><table cellspacing=0 cellpadding=0 border=0 style="display:none;"><tr><td width=1 class=ob_ic> </td><td><table cellspacing=0 cellpadding=0 border=0 class=ob_zz><tr><td width=1 class=ob_ic><img width=16 class=ob_ic src='/_tree/xpPanel.gif'></td><td id=d3 onclick='ob_ft(this)' class=ob_td><input type=checkbox name=sIteID value=3_01B94E4C-A21A-4C76-920E-C2B9773CE2B8><STRONG>Site3>Unit3</STRONG><input type=hidden name=sup_ value={01B94E4C-A21A-4C76-920E-C2B9773CE2B8}></td><td align=right></td></tr></table></td></tr></table></td></tr></table></td></tr></table></td></tr></table></div>
<SCRIPT LANGUAGE="JavaScript"><!--
ob_ft(b1);
//--></script>
<!-- ASP TreeView component http://www.obout.com -->