divtree.js 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. var loadTip = "<div>���װ���У����Ժ�...</div>";
  2. function Zid(idstr) {
  3. try {
  4. return window.document.getElementById(idstr);
  5. } catch (e) {
  6. alert("function Zid:" + e.description);
  7. }
  8. }
  9. function send_request(url, postData, aObjectID) { // ��ʼ����ָ�����?��������ĺ���
  10. // ��ʼ��ʼ��XMLHttpRequest����
  11. var http_request;
  12. if (window.XMLHttpRequest) { // Mozilla �����
  13. http_request = new XMLHttpRequest();
  14. if (http_request.overrideMimeType) {// ����MiME���
  15. http_request.overrideMimeType("text/xml");
  16. }
  17. } else if (window.ActiveXObject) { // IE�����
  18. try {
  19. http_request = new ActiveXObject("Msxml2.XMLHTTP");
  20. } catch (e) {
  21. try {
  22. http_request = new ActiveXObject("Microsoft.XMLHTTP");
  23. } catch (e) {
  24. }
  25. }
  26. }
  27. if (!http_request) { // �쳣����������ʵ��ʧ��
  28. window.alert("���ܴ���XMLHttpRequest����ʵ��.");
  29. return false;
  30. }
  31. http_request.onreadystatechange = getReadyStateHandler(http_request,
  32. aObjectID);
  33. // ȷ����������ķ�ʽ��URL�Լ��Ƿ�ͬ��ִ���¶δ���
  34. http_request.open("POST", url, true);
  35. http_request.setRequestHeader("Content-Type",
  36. "application/x-www-form-urlencoded");
  37. http_request.send(postData);
  38. }
  39. function getReadyStateHandler(req, aObjectID) {
  40. // ����һ������XMLHttpRequestʵ���������
  41. return function() {
  42. // ��������״̬�ǡ���ɡ�
  43. if (req.readyState == 4) {
  44. // �ɹ������˷�������Ӧ
  45. if (req.status == 200) {
  46. var temp = Zid(aObjectID);
  47. if (temp == null) {
  48. alert('can not find object');
  49. } else {
  50. temp.style.display = "";
  51. temp.innerHTML = req.responseText;
  52. }
  53. } else {
  54. // ��HTTP���ⷢ��
  55. alert("HTTP error: " + req.status);
  56. }
  57. }
  58. }
  59. }
  60. function expand(aObjectID) {
  61. var spanChild = Zid(aObjectID + "child");
  62. if (spanChild.innerHTML != "") {
  63. // ͼƬ����
  64. if (spanChild.style.display == "") {
  65. Zid(aObjectID + "img").src = treeImagePath + treeCloseImg;
  66. spanChild.style.display = "none";
  67. } else if (spanChild.style.display == "none") {
  68. Zid(aObjectID + "img").src = treeImagePath + treeOpenImg;
  69. spanChild.style.display = "";
  70. }
  71. } else {
  72. Zid(aObjectID + "img").src = treeImagePath + treeOpenImg;
  73. spanChild.innerHTML = loadTip;
  74. var postData = "nodeID=" + aObjectID + "&buildSelf=false";
  75. send_request(url, postData, aObjectID + "child");
  76. }
  77. }
  78. // ˢ�¸�nodeID�ڵ�
  79. function refreshNode(nodeID) {
  80. var postData;
  81. var aDivObject;
  82. if (nodeID == "") {
  83. nodeID = "rootID";
  84. postData = "nodeID=&buildSelf=true";
  85. } else {
  86. postData = "nodeID=" + nodeID + "&buildSelf=true";
  87. }
  88. aDivObject = Zid(nodeID);
  89. aDivObject.innerHTML = loadTip;
  90. send_request(url, postData, nodeID);
  91. }
  92. function openNewPage() {
  93. window.open(url, null,
  94. "height=600,width=800,status=0,toolbar=0,scrollbars=1");
  95. }