JavaScript之充实文档的内容

1、我们在平时的开发中会碰到一些缩略语如:XML,HTML,API等专业术语;为了能使用户,更好的了解术语的意思,我们通常会给<abbr></abbr>标签加一个title属性来放术语的全称,但是有些浏览器可能不会显示title属性,所以我们通过JS来动态的加载并显示缩略语和他的全称。代码如下:

js代码:

window.οnlοad=displayAbbreviations;
//处理文档中的缩略语,用JS生成一个列表用来显示对应的缩略语的具体含义
//produce a list of Abbreviation by js to deal with the Abbreviation in the document
function displayAbbreviations() {
    if (!checkCompatibility()) return;   //检查兼容性
    var abbreviations = document.getElementsByTagName("abbr"); //提取所有的缩略词标签
    if (abbreviations.length < 1) return false;
    var defs = new Array();
    for (var i = 0; i < abbreviations.length; i++) {
        var key = abbreviations[i].firstChild.nodeValue;//标签的文本值当key
        var definition = abbreviations[i].getAttribute("title"); //标签的title属性值当value;
        defs[key] = definition;
    }
    //创建缩略词展示列表
    var dllist = document.createElement("dl");
    for (key in defs) { 
        //创建缩略词标题
        var dt=document.createElement("dt");
        var tit = document.createTextNode(key);
        dt.appendChild(tit);
        //创建描述
        var dd = document.createElement("dd");
        var descri = document.createTextNode(defs[key]);
        dd.appendChild(descri);
        dllist.appendChild(dt);
        dllist.appendChild(dd);
    }
    document.getElementsByTagName("body")[0].appendChild(dllist);
}
/*
检查浏览器的兼容性,是否支持查用的DOM方法
check the compatibility of the broswer
*/
function checkCompatibility() {
    if (!document.getElementById) return false;
    if (!document.createElement) return false;
    if (!document.createTextNode) return false;
    if (!document.getElementsByTagName) return false;
    if (!document.getElementsByName) return false;
    return true;
}

html:

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <script src="js/index.js" type="text/javascript"></script>
</head>
<body>
<h1>What is the Document Object Model?</h1>
<p>The <abbr title="World Wide Web Consortium(联合)">W3C</abbr> defines the <abbr title="Document Object Model">DOM</abbr> as:</p>
<blockquote cite="http://www.w3.org/DOM/" title="W3C">
   <p>
   A platform- and language-neutral(中立语言) interface that will allows paograms and scripts to dynamically access and update the
   content,structrue and the style of documents.
   </p>
</blockquote>
<p>
It is an <abbr title="Application Programming Interface">API</abbr> that can be used to navigate(驾驶,操控) <abbr title="HyperText MarkUp Language">HTML</abbr>
and <abbr title="eXtensible MarkUp Language">XML</abbr>
</p>
<h1>Abbreviation(缩略语列表)</h1>
</body>
</html>

效果如图:

 

我们在写博客和文章的经常引用别人的文章,这个时候我们会说明这段文档的出处,我们在开发时亦是如此:这个时候我们可以给我们引用的段落用一个<blockquote></blockquote>包围,然后在里面加一个cite属性(文章出处的链接地址)标明出处,然后通过JS将地址动态的加载到引用段落的最后位置。代码如下:

js代码:

/*
检查浏览器的兼容性,是否支持查用的DOM方法
check the compatibility of the broswer
*/
function checkCompatibility() {
    if (!document.getElementById) return false;
    if (!document.createElement) return false;
    if (!document.createTextNode) return false;
    if (!document.getElementsByTagName) return false;
    if (!document.getElementsByName) return false;
    return true;
}
//文献来源链接表     在引用的文档的末尾添加引用的具体地址
//The literature source list      function:add  specific adress to end of the  reference document
function getLiteratureSourceList() {
    if (!checkCompatibility()) return;   //检查兼容性
    if (!document.getElementsByTagName("blockquote")) return false;
    var quotes =document.getElementsByTagName("blockquote");
    for (var i = 0; i < quotes.length; i++) {
        var cite = quotes[i].getAttribute("cite") != "" ? quotes[i].getAttribute("cite") : "javascript:void(0)"; //get reallink
        var from = quotes[i].getAttribute("title") == "" ? "" : "from   "+quotes[i].getAttribute("title");  //get the origin of the document
        var link = document.createElement("a");
        link.setAttribute("href", cite); //set href to a
        var txt = document.createTextNode(from);
        link.appendChild(txt);
        quotes[i].appendChild(link);
    }
}
//The literature source list end

html代码如下:

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <script src="js/utility.js" type="text/javascript"></script>
    <script src="js/index.js" type="text/javascript"></script>
</head>
<body>
<h1>What is the Document Object Model?</h1>
<p>The <abbr title="World Wide Web Consortium(联合)">W3C</abbr> defines the <abbr title="Document Object Model">DOM</abbr> as:</p>
<blockquote cite="http://www.w3.org/DOM/" title="W3C">
   <p>
   A platform- and language-neutral(中立语言) interface that will allows paograms and scripts to dynamically access and update the
   content,structrue and the style of documents.
   </p>
</blockquote>
<p>
It is an <abbr title="Application Programming Interface">API</abbr> that can be used to navigate(驾驶,操控) <abbr title="HyperText MarkUp Language">HTML</abbr>
and <abbr title="eXtensible MarkUp Language">XML</abbr>
</p>
<h1>Abbreviation(缩略语列表)</h1>
</body>
</html>

效果如下:

from  w3c  表明了出处,超链接也指向了来源的地方.

 

在html元素的属性里有一个accseekey属性,这个属性可以把一个元素与键盘上的某个特定按键关联在一起,这对那些不能或不喜欢使用鼠标来浏览网页的人们很有用。对于有视力障碍的人士,键盘快捷方式肯定会带来方便。

注意:设置太多的快捷键往往会适得其反,他们或许可能会与浏览器内建的键盘快捷方式发生冲突。

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <script src="js/utility.js" type="text/javascript"></script>
    <script src="js/index.js" type="text/javascript"></script>
</head>
<body>
<ul id="navigation">
<li><a href="javascript:void(0)" accesskey="1">Home</a></li>
<li><a href="javascript:void(0)" accesskey="4">Search</a></li>
<li><a href="javascript:void(0)" accesskey="9">Contact</a></li>
</ul>
<h1>What is the Document Object Model?</h1>
<p>The <abbr title="World Wide Web Consortium(联合)">W3C</abbr> defines the <abbr title="Document Object Model">DOM</abbr> as:</p>
<blockquote cite="http://www.w3.org/DOM/" title="W3C">
   <p>
   A platform- and language-neutral(中立语言) interface that will allows paograms and scripts to dynamically access and update the
   content,structrue and the style of documents.
   </p>
</blockquote>
<p>
It is an <abbr title="Application Programming Interface">API</abbr> that can be used to navigate(驾驶,操控) <abbr title="HyperText MarkUp Language">HTML</abbr>
and <abbr title="eXtensible MarkUp Language">XML</abbr>
</p>
<h1>Abbreviation(缩略语列表)</h1>
</body>
</html>

js代码:

//展示网页快捷键清单
//display the list of shortcut key 
function displayAccessKeys() {
    if (!checkCompatibility()) return;   //check compatibility
    var links = document.getElementsByTagName("a");
    var keys = new Array();
    for (var i = 0; i < links.length; i++) {
        var current_link = links[i];
        if (!current_link.getAttribute("accesskey")) continue;
        var key = current_link.getAttribute("accesskey"); //get the key
        var text = current_link.firstChild.nodeValue;   //get the description
        keys[key] = text;
    }
    var ul = document.createElement("ul");
    for (key in keys) {
        var li = document.createElement("li");
        var li_txt = key + " : " + keys[key];
        var item = document.createTextNode(li_txt);
        li.appendChild(item);
        ul.appendChild(li);
    }
    var tit = document.createElement("h3");
    var tit_text = document.createTextNode("state of shortcut key(快捷键说明)");
    tit.appendChild(tit_text);
    document.getElementsByTagName("body")[0].appendChild(tit);
    document.getElementsByTagName("body")[0].appendChild(ul);
}
//display the list of shortcut key  end

/*
检查浏览器的兼容性,是否支持查用的DOM方法
check the compatibility of the broswer
*/
function checkCompatibility() {
    if (!document.getElementById) return false;
    if (!document.createElement) return false;
    if (!document.createTextNode) return false;
    if (!document.getElementsByTagName) return false;
    if (!document.getElementsByName) return false;
    return true;
}

输出如下:

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: Ext JS 6.2是一个流行的JavaScript框架,用于构建富客户端应用程序。关于Ext JS 6.2的中文文档,有以下几个重要的方面: 1.官方文档:Ext JS官方网站提供了详细的中文文档,包括了框架的各个模块和组件的使用说明、API参考和示例代码。这些文档可以帮助开发人员快速了解如何使用Ext JS构建应用程序,并解决开发过程中的问题。 2.社区支持:由于Ext JS在开发者社区中非常受欢迎,有很多热心的开发者积极参与提供中文文档的翻译和整理。在各大技术论坛、博客和社交媒体上,都可以找到很多中文的教程、指南和技术文章,为初学者和有经验的开发人员提供了非常有价值的参考。 3.书籍和教程:对于希望深入学习Ext JS 6.2的开发人员来说,有一些中文书籍和在线教程可供选择。这些资源通常会更加详细地介绍框架的各个方面,包括架构设计、数据模型、UI组件、事件处理等。读者可以根据自己的需求选择适合自己的学习材料,进一步掌握Ext JS的应用。 总之,有关Ext JS 6.2的中文文档是非常充实和丰富的,通过官方文档、社区支持以及书籍和教程,开发人员可以轻松地学习和应用这个强大的JavaScript框架。无论是初学者还是有经验的开发人员,都可以从中文文档中获得帮助,并快速开发出高质量的富客户端应用程序。 ### 回答2: ExtJS 6.2 是一种流行的JavaScript 库,用于构建跨浏览器、跨平台的富客户端应用程序。它提供了丰富的组件和功能,可以简化开发人员创建复杂应用程序的过程。 ExtJS 6.2 中文文档的存在对于中文开发者来说非常重要。首先,它提供了一个方便的学习资源,使开发者可以详细了解 ExtJS 的各种功能和用法。通过阅读中文文档,开发者可以更轻松地理解框架内部的工作原理,并能够更高效地使用和应用 ExtJS。 其次,中文文档可以帮助开发者更好地沟通和交流。对于中文开发者来说,使用母语来解释和讨论问题会更容易和准确。通过中文文档,开发者可以更好地理解 ExtJS 的各种概念和术语,并能够更方便地与其他开发者交流和合作。 最后,中文文档还可以提供更好的开发支持和问题解答。当开发者在使用 ExtJS 过程中遇到问题或困惑时,他们可以通过查阅中文文档来获得解答。文档中通常包含了常见问题和示例代码,这些资源对于开发者的开发过程非常有帮助。 总的来说,ExtJS 6.2 中文文档是一个非常重要的资源,对中文开发者来说具有巨大的价值。它提供了学习、交流和问题解答的支持,能够帮助中文开发者更好地理解和应用 ExtJS。 ### 回答3: ExtJS 6.2是一种用于构建现代化Web应用程序的前端开发框架。该框架拥有丰富的UI组件和面向对象的开发风格,使开发者能够轻松地创建高度可定制的用户界面。 对于中文文档,ExtJS 6.2提供了全面而详细的中文文档。其中包括了框架的各个方面,如组件、布局、数据绑定、事件处理、表单验证、网络通信等等。文档使用清晰的中文描述和简洁的示例代码,方便开发者理解和学习。 在中文文档中,开发者可以快速了解到ExtJS 6.2的各个功能模块,并且能够按照自己的需要进行深入学习。文档提供了大量的示例代码,使开发者可以快速上手并且实现自己的需求。 另外,ExtJS 6.2中文文档还提供了丰富的API文档,详细介绍了每个组件和类的属性、方法和事件,让开发者可以方便地查阅和使用相关API。 总之,ExtJS 6.2中文文档是一份全面而易于理解的官方文档,为开发者提供了详尽的使用指南和参考资料,有助于开发者快速掌握和应用该框架,实现高质量的Web应用程序开发。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值