XML + XSL + JS 构建小型Web App (十五)

来源:互联网 发布:诗句在线生成器软件 编辑:程序博客网 时间:2024/06/01 07:32

4. index.htm.files/js/common.js

下面列出common.js 文件中 和显示功能相关的函数,其他函数后面详细叙述。

// 文件名 :common.js 
// 常用 javascript 函数的声明
// 作者 : 刘海龙
// xiaoleilong@mail.biti.edu.cn
// 2003年8月1日

//初始化 需要显示的内容
function init()
{
 var coll = document.all.tags("DIV");
 var i;
 for (i=0;i<3;i++ )
  coll[i].style.display = "none"; 
 coll[0].innerHTML = do_trans("index.htm.files/data/record.xml","index.htm.files/styles/normal.xsl");//显示视图
 coll[1].innerHTML = get_edit_view();
 coll[2].innerHTML = get_set_view();
 
}
/** 函数 do_trans((strXmlPath , strXslPath)
   * 参数:分别指定 xml 文件 和 xsl 文件的路径
   * 功能:使用 xsl 对 xml 进行转换
   * 返回:转换得到的字符串
   */
function do_trans(strXmlPath , strXslPath)
{
    // Load XML
    var xml = new ActiveXObject("Microsoft.XMLDOM")
    xml.async = false
    xml.load(strXmlPath)
    // Load the XSL
    var xsl = new ActiveXObject("Microsoft.XMLDOM")
    xsl.async = false
    xsl.load(strXslPath)
    // Transform
 return xml.transformNode(xsl);
}

/** 函数 disp_spec_sect(section)
   * 参数:指定将切换到的页面 , 其中 : disp -- 显示简历的页面 ; edit -- 编辑简历的页面 ; set -- 进行基本设置的页面 。
   * 功能:根据 section 参数的取值, 切换显示到指定的页面 。
   * 返回:无返回值
   */
function disp_spec_sect(section)
{
 var coll = document.all.tags("DIV");
 if (coll != null)
 {
  for (i=0; i<coll.length; i++)
   coll[i].style.display = "none";
 }
 document.getElementById(section+"").style.display = "block";
}

原创粉丝点击