/// <summary>
/// 方法GenerateScript用于生成Javascript代码,不使用任何变量或参数
/// </summary>
/// <returns></returns>
private string GenerateScript()
{
string tempScript;
tempScript = "\n<SCRIPT LANGUAGE=\"JavaScript\">\n";
tempScript = tempScript + "<!----------------------------------------------------------\n";
tempScript = tempScript + "//此处为控件CashMenu的客户端代码\n";
tempScript = tempScript + "//Cash版权所有 有问题请致电邮[email protected]\n";
tempScript = tempScript + "//版本号:beta1\n";
tempScript = tempScript + "//2003年1月7日\n";
tempScript = tempScript + "menuPrefix = 'menu';\n";
tempScript = tempScript + "var menuTree, mouseMenu, hideTimer, doHide;\n";
tempScript = tempScript + "function init() \n";
tempScript = tempScript + "{\n";
tempScript = tempScript + "\tie4 = (document.all)?true:false;\n";
tempScript = tempScript + "\tns4 = (document.layers)?true:false;\n";
tempScript = tempScript + "\tdocument.onmousemove = mouseMove;\n";
tempScript = tempScript + "\tif (ns4) { document.captureEvents(Event.MOUSEMOVE); }\n";
tempScript = tempScript + "}\n";
tempScript = tempScript + "function expandMenu(menuContainer,subContainer,menuLeft,menuTop) {\n";
tempScript = tempScript + "// 隐去所有\n";
tempScript = tempScript + "\tdoHide = false;\n";
tempScript = tempScript + "\tif (menuContainer != menuTree) {\n";
tempScript = tempScript + "\tif (ie4) {\n";
tempScript = tempScript + "\t\tvar menuLayers = document.all.tags(\"DIV\");\n";
tempScript = tempScript + "\t\tfor (i=0; i<menuLayers.length; i++) {\n";
tempScript = tempScript + "\t\t\tif ((menuLayers[i].id.indexOf(menuContainer) != -1) && (menuLayers[i].id != menuContainer)) {\n";
tempScript = tempScript + "\t\t\t\thideObject(menuLayers[i].id);\n";
tempScript = tempScript + "\t\t\t}\n";
tempScript = tempScript + "\t\t }\n";
tempScript = tempScript + "\t\t}\n";
tempScript = tempScript + "\telse if (ns4) {\n";
tempScript = tempScript + "\t\tfor (i=0; i<document.layers.length; i++) {\n";
tempScript = tempScript + "\t\t\tvar menuLayer = document.layers[i];\n";
tempScript = tempScript + "\t\t\tif ((menuLayer.id.indexOf(menuContainer) != -1) && (menuLayer.id != menuContainer)) {\n";
tempScript = tempScript + "\t\t\t\tmenuLayer.visibility = \"hide\";\n";
tempScript = tempScript + "\t\t\t}\n";
tempScript = tempScript + "\t\t}\n";
tempScript = tempScript + "\t}\n";
tempScript = tempScript + "}\n";
tempScript = tempScript + "// 打开或\n";
tempScript = tempScript + "if (subContainer) {\n";
tempScript = tempScript + "\tif ((menuLeft) && (menuTop)) {\n";
tempScript = tempScript + "\t\tpositionObject(subContainer,menuLeft,menuTop);\n";
tempScript = tempScript + "\t\thideAll();\n";
tempScript = tempScript + "\t}\n";
tempScript = tempScript + "else {\n";
tempScript = tempScript + "\t\tif (ie4) {\n";
tempScript = tempScript + "\t\tpositionObject(subContainer, document.all[menuContainer].offsetWidth + document.all[menuContainer].style.pixelLeft - 10, mouseY);\n";
tempScript = tempScript + "\t}\n";
tempScript = tempScript + "else {\n";
tempScript = tempScript + "\tpositionObject(subContainer, document.layers[menuContainer].document.width + document.layers[menuContainer].left + 50, mouseY);\n";
tempScript = tempScript + "}\n";
tempScript = tempScript + "}\n";
tempScript = tempScript + "showObject(subContainer);\n";
tempScript = tempScript + "menuTree = subContainer;\n";
tempScript = tempScript + "}\n";
tempScript = tempScript + "}\n";
tempScript = tempScript + "function showObject(obj) {\n";
tempScript = tempScript + "\tif (ie4) { document.all[obj].style.visibility = \"visible\"; }\n";
tempScript = tempScript + "\t\telse if (ns4) { document.layers[obj].visibility = \"show\"; }\n";
tempScript = tempScript + "\t}\n";
tempScript = tempScript + "function hideObject(obj) {\n";
tempScript = tempScript + "\tif (ie4) { document.all[obj].style.visibility = \"hidden\"; }\n";
tempScript = tempScript + "\t\telse if (ns4) { document.layers[obj].visibility = \"hide\"; }\n";
tempScript = tempScript + "\t}\n";
tempScript = tempScript + "function positionObject(obj,x,y){\n";
tempScript = tempScript + "\tif (ie4) {\n";
tempScript = tempScript + "\t\tvar foo = document.all[obj].style;\n";
tempScript = tempScript + "\t\tfoo.left = x;\n";
tempScript = tempScript + "\t\tfoo.top = y;\n";
tempScript = tempScript + "\t}\n";
tempScript = tempScript + "\telse if (ns4) {\n";
tempScript = tempScript + "\t\tvar foo = document.layers[obj];\n";
tempScript = tempScript + "\t\tfoo.left = x;\n";
tempScript = tempScript + "\t\tfoo.top = y;\n";
tempScript = tempScript + "\t}\n";
tempScript = tempScript + "}\n";
tempScript = tempScript + "function hideAll() \n";
tempScript = tempScript + "{\n";
tempScript = tempScript + " if (ie4) \n";
tempScript = tempScript + " {\n";
tempScript = tempScript + "\t\t\tvar menuLayers = document.all.tags(\"DIV\");\n";
tempScript = tempScript + "\t\t\tfor (i=0; i<menuLayers.length; i++) \n";
tempScript = tempScript + "\t\t\t{\n";
tempScript = tempScript + "\t\tif (menuLayers[i].id.indexOf(menuPrefix) != -1) \n";
tempScript = tempScript + "\t\t{\n";
tempScript = tempScript + "\t\t\thideObject(menuLayers[i].id);\n";
tempScript = tempScript + "\t\t}\n";
tempScript = tempScript + "\t}\n";
tempScript = tempScript + "}\n";
tempScript = tempScript + "\telse if (ns4) \n";
tempScript = tempScript + "\t{\n";
tempScript = tempScript + "\tfor (i=0; i<document.layers.length; i++) \n";
tempScript = tempScript + "\t\t{\n";
tempScript = tempScript + "\t\t\tvar menuLayer = document.layers[i];\n";
tempScript = tempScript + "\t\t\tif (menuLayer.id.indexOf(menuPrefix) != -1) \n";
tempScript = tempScript + "\t\t\t{\n";
tempScript = tempScript + "\t\t\t\thideObject(menuLayer.id);\n";
tempScript = tempScript + "\t\t\t}\n";
tempScript = tempScript + "\t\t}\n";
tempScript = tempScript + "\t\t}\n";
tempScript = tempScript + "\t}\n";
tempScript = tempScript + "function hideMe(hide) \n";
tempScript = tempScript + "{\n";
tempScript = tempScript + "\tif (hide) \n";
tempScript = tempScript + "\t{\n";
tempScript = tempScript + "\t\tif (doHide) { hideAll(); }\n";
tempScript = tempScript + "\t}\n";
tempScript = tempScript + "\telse\n";
tempScript = tempScript + "\t{\n";
tempScript = tempScript + "\t\tdoHide = true;\n";
tempScript = tempScript + "\t\thideTimer = window.setTimeout(\"hideMe(true);\", 2000);\n";
tempScript = tempScript + "\t}\n";
tempScript = tempScript + "}\n";
tempScript = tempScript + "function mouseMove(e) \n";
tempScript = tempScript + "{\n";
tempScript = tempScript + "\tif (ie4) { mouseY = window.event.y; }\n";
tempScript = tempScript + "\tif (ns4) { mouseY = e.pageY; }\n";
tempScript = tempScript + "}\n";
tempScript = tempScript + "function itemHover(obj,src,text,style) \n";
tempScript = tempScript + "{\n";
tempScript = tempScript + "\tif (ns4) \n";
tempScript = tempScript + "\t{\n";
tempScript = tempScript + "\t\tvar text = '<nobr><a href=\"' + src + '\" class=\"' + style + '\">' + text + '<\\/a><\\/nobr>'\n";
tempScript = tempScript + "\t\tobj.document.open();\n";
tempScript = tempScript + "\t\tobj.document.write(text);\n";
tempScript = tempScript + "\t\tobj.document.close();\n";
tempScript = tempScript + "\t}\n";
tempScript = tempScript + "}\n";
tempScript = tempScript + "onload = init;\n";
tempScript = tempScript + "//-->\n";
tempScript = tempScript + "</SCRIPT>\n";
tempScript = tempScript + "\n";
return(tempScript);
}
本文地址:http://com.8s8s.com/it/it45656.htm