`

title用法

阅读更多
定义和用法
title 属性可设置或返回对元素的描述性短语。

语法
bodyObject.title=title

example1:
<body id="myid" title="mytitle">
<script type="text/javascript">
x=document.getElementsByTagName('body')[0];
document.write("Body title: " + x.title);
document.write("<br />");
document.write("An alternate way: ");
document.write(document.getElementById('myid').title);
</script>
</body> 


example2:
<a href="http://www.baidu.com/" title="begin XHTML study">XHTML学习</a>


说明
可以为链接,表单等元素提供额外的信息(HTML中所有元素都具有title属性),比如可以通过title属性详细介绍要链接到的页面的内容.
鼠标停留在链接或表单上面时,显示提示文字.
一些可以发音的浏览器,可以说出"title"里的内容

example3:
带换行的title测试
<div title="123&#10;456">text</div>
<div title="123& #10;456">text</div>
<a   href=""   title="怎样强&#13;制换行">留言</a>  
 
<div title="I am a happy girl, I am very happy. I want to be happy forever.That's the words I want to say to everybody, I hope everyone will be happy every day.">long text</div>



ToolTip Torture Test
Tooltips can be very useful things, but there are a few intracies that most authors don’t understand how to take advantage of, and a few behaviors that are bugs in the various browser implementations.

Several attributes should cause a tooltip or similar display when the cursor is passed over an object with some or all of them. title should always display its contents, while alt should only be displayed when the image has not been loaded. I am not sure how longdesc should be handled; it is paired with alt in the HTML 4.01 specification, and seems designed to provide a textual description of the image in lieu of actually showing the image (primarially for blind people, perhaps), but the spec is silent on this, and it could be used simply as a means for providing an extended description or information about the image appropriate for all users. Therefore, it is my contention that this link should always be displayed.

TITLE & ALT
Move your mouse cursor over the checkmark, and you should see a tooltip with the phrase, “This is a checkmark.” displayed near the cursor. If it displays “checkmark image” instead, your browser is displaying the title attribute instead.
TITLE, ALT, & LONGDESC
This image should display a tooltip identical to the one above, but it should also have some sort of a hyperlink displayed near or attached to it. A URL is specified in the LONGDESC attribute of that image tag.
Really Long Text
This image has an extremely long text string specified as the ALT text. The string ends with “…will be gray.” and you should see that.
Ignoring Line Breaks
This image’s ALT text is four sentences, with a line break between each sentence. According to the HTML specification, these line breaks should be ignored, but Internet Explorer 6.0 interprets them; putting each sentence on a new line of the tooltip. This is both useful and problematic behavior—and very incorrect. The HTML specification should be modified to allow for simple formatting such as line breaks, bolding, and itallics.
Forcing Line Breaks
The HTML specification specifies that all linefeeds shall be ignored, but some method of indicating them in tooltips is needed. Two methods that occur to me are using &#8232; (Unicode NewLine) or /A (CSS2 escape sequence for a traditional newline).
Typesetting Character Entities
This tooltip should contain several typesetting characters, including an em dash after checkmark, a built fraction for 1/4 and double prime for 1/4 inch, curly quotes around feature chart, and an ellipsis at the end.
UTF-8 Typesetting Characters
This tooltip should contain several typesetting characters, including an em dash after checkmark, a built fraction for 1/4 and double prime for 1/4 inch, curly quotes around feature chart, and an ellipsis at the end.

大概的意思是,XHTML DTD定义title属性为一个CDATA,而根据SGML里CDATA的定义,浏览器应该:替换所有html实体;忽略LF字符;替换所有CR字符和tab字符为一个空格。

按照W3C的说法,执行这3步后,所有的CR和LF字符已经他们的html实体都已消失或变成空格了。看起来在title里换行变成不可能的事了。不过,Firefox好像并没有转换CR字符为空格,而是把CR给忽略了。而LF字符倒是没有被处理,直接换行了。上面的代码,不用UNIX行尾符LF,而是用Mac行尾符CR,在IE下还能换行,但是在Firefox下,CR字符直接被忽略了。我还是很想通过W3C的验证,所以做了一下测试,使用LF字符或者LF的html实体& #10;都是可以的。网上流传说可以用CR的html实体& #13;,其实只是IE中可以,Firefox下一样不行。如果不追求符合W3C,那还不如直接把字符串转成UNIX行尾符输出呢

还有,title里有小于号和单引号好像并不要紧,但是有双引号就不行了。这么说来,把字符串里的换行和双引号给替换一下输出就行了?go on learning...
分享到:
评论

相关推荐

    get_title.py

    资产处理小工具,python3编写,功能简单,大佬勿喷,批量访问网址,并获取title 使用方法:scanport扫描出来的结果存入res.txt,可直接使用get_title.py获取title

    使用vue-router设置每个页面的title方法

    基本环境配置: webpack + vue2.0 + vue-router +nodeJS 进入 router 文件夹底下的index.js文件 首先引入: import Vue from 'vue' import Router from 'vue-... title: '首页入口' } }, { /* 修改昵称 */ path: '

    android改变title步骤

    自定义title的使用方法,可以改变title的样式

    使用vue-router为每个路由配置各自的title

    如果想要动态的去修改,需要使用如下的方法。 document.title = '这是一个标题'; 这样会让我们做很多无用功。显得十分蠢。 使用Vue-Router的方法 首先打开/src/router/index.js文件。 找到如下代码。 const vue...

    pdftitle:提取PDF文章标题的实用程序

    pdf标题 pdftitle是提取PDF文章标题的小...安装 pip install pdftitle用法pdftitle -p 返回找到的文档标题。 $ pdftitle -p knuth65.pdf On the Translation of Languages from Left to Rightpdftitle -p &lt;pdf-fi

    react-router-doc-title:当React Route更改时更新页面标题。 同时向屏幕阅读器宣布新标题。 在制品! 演示版

    react-router-doc-title 使用React Router更改路线时更新页面标题。 同时向屏幕阅读器宣布新标题。 受到对Ember.js和。 注意:正在进行中!要求经过测试: react ^0.13 react-router ^1.0.0-rc1安装npm install --...

    Jquery编写的替换系统title提示

    此代码使用jquery编写,直接让网页加载这个JS即可替换原来的title提示,如果你懂一点代码,还可以进入这个JS进行修改样式。本人亲自编写测试成功通过,如果对您有用,请给予支持。(baiyukey.blog.163.com)

    set-terminal-title:为您的 Node.js 进程设置终端标题

    用法 语法是setTerminalTitle(, ) ,其中opts是一个对象。 选项 冗长的 类型: Boolean默认值: false 将注销您正在设置终端标题 记录器 类型: Object默认值: console 要使用的记录器实例。 需要有一个info方法...

    关于alt和title的用法区别详解

    现在我对他们两个的用法做一下总结: 相同点:他们都会飘出一个小浮层,显示文本内容。 不同点: 1.alt只能是元素的属性,而title即可以是元素的属性也可以是标签,例如:&lt;title&gt;标题&lt;/title&gt;。 2.alt...

    Python中title()方法的使用简介

    下面的例子显示了title()方法的使用。 #!/usr/bin/python str = "this is string example....wow!!!"; print str.title(); 当我们运行上面的程序,它会产生以下结果: This Is String Example....Wow!!!

    flash-document-title:在标签标题区域闪烁通知消息

    Flash文档标题 ... 通过创建添加事件侦听器的商店,可以在choo视图中轻松使用它: var app = choo ( ) app . use ( flashStore ) function flashStore ( state , emitter ) { emitter . on ( 'notify'

    vue动态设置页面title的方法实例

    本文主要介绍了Vue动态修改title的方法,需要的朋友可以参考学习,方法如下: 1.通过自定义指令去修改(单个修改比较好) //1.在main.js 页面里添加自定义指令 Vue.directive('title', {//单个修改标题 inserted: ...

    html-webpack-plugin修改页面的title的方法

    vue-cli2.X:修改config目录下index.js const title = '标题1' ...接着就可以在webpack.dev.conf.js, webpack.prod.conf.js中的HtmlWebpackPlugin使用config.title new HtmlWebpackPlugin({ title: c

    零基础学HTML CSS源代码

    title用法.html 链接参数title用法。 锚点链接.html 标记锚点链接用法 图片链接.html 演示图片链接。 文字链接....

    article-title:提取HTML文档的文章标题

    也没有标准化的方法在标记中指示文章的标题。 该模块使用一些试探法将其干净地提取出来。 安装 $ npm install article-title 用法 import articleTitle from 'article-title' ; const html = ` &lt;!doctype html&gt; ...

    angular-painless-title:一个简单易用(无痛)的模块,用于在 Angular 应用程序中操作标题

    用法 包含脚本,您必须在 html 元素处设置 ng-app,然后绑定 title 元素。 &lt;!doctype html &gt; &lt; html ng-app =" dummyApp " &gt; &lt; head &gt; &lt;!-- You should define a title value, so a robot can ...

    document-title:React挂钩,用于更新文档标题

    您需要在^16.7.0-alpha.0安装react , react-dom等安装yarn add @rehooks/document-title用法import useDocumentTitle from '@rehooks/document-title' ;function MyComponent ( ) { useDocumentTitle ( 'Page ...

    title-notify:用页面标题通知的简单插件

    #安装 Bower 支持 bower install title - notify #Usage 现在支持两种类型:flash、scroll。 闪光效果这是默认效果,因此效果选项是不必要的。 该消息将根据间隔配置定期显示和隐藏。 titleNotify . init ( { ...

    详解WordPress开发中wp_title()函数的用法

    wp_title 函数在 WordPress 中是用来...有点像 WordPress 中的 get_the_title 和 single_cat_title()这两个函数的自适应用法(自动判断是页面、文章还是分类、归档、标签)。 函数声明 有点长,希望您能耐心看一遍,

    Actual Title Buttons 8.5简体中文破解版.rar

    Actual Title Buttons可以更改标题栏按钮皮肤,对窗口菜单项目进行排序,更改窗口尺寸大小,用于对任务栏中的图标进行修改增加其他功能按钮。窗口缩略图功能:在鼠标移动到如下对象时,以提示信息的方式显示窗口...

Global site tag (gtag.js) - Google Analytics