`

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

    title滚动页面title滚动

    实现title滚动和页面title滚动的方法多种多样,以下是两种常见的技术途径: 1. CSS3动画:利用CSS3的`@keyframes`规则,我们可以定义一个标题从一端移动到另一端的动画。通过设置`animation`属性,将这个动画应用到...

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

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

    Vue项目添加动态浏览器头部title的方法

    为了更加规范和模块化,我们可以将设置title的方法导出为一个函数,使其能在其他部分的代码中被导入使用。此外,也可以利用Vue Router提供的afterEach钩子函数,在每次路由跳转后执行设置title的操作。afterEach钩子...

    python抽取指定url页面的title方法

    今天我们讨论的主题是“Python抽取指定url页面的title方法”,这是一个网络爬虫中非常常见的需求,即从网页源码中提取出网页的标题信息。 首先,要实现这个功能,我们需要了解两个Python中常用的模块:re和lxml。re...

    ECSHOP商品详情页 增加自定义TITLE的方法

    否则,将使用默认的页面标题。 最后,为了使上述更改生效,别忘了在后台清除缓存。这样,所有步骤完成后,ECSHOP的商品详情页就能够显示自定义的TITLE,从而更好地展示商品信息,提高搜索引擎的可见性,同时也满足...

    Test404轻量Title获取器 v2.0

    Test404轻量Title获取器 v2.0是一款专为网络优化和SEO专业人士设计的高效工具,其主要功能是快速地从互联网上批量获取网页的Title信息...然而,使用任何工具都应遵循正确的使用方法和道德规范,以保持良好的网络环境。

    matlab绘制图形设定title的位置

    #### 二、设定Title位置的方法 1. **使用`'position'`属性**: - 默认情况下,`title`函数会将标题放置在坐标轴的顶部中央。 - 如果需要将标题放置在一个特定的位置,可以通过设置`'position'`属性来实现。 - `...

    利用链接里面的title做不一样的title效果

    首先,`title`属性在HTML中的基本用法是在任何元素上添加,例如: ```html &lt;a href="http://example.com" title="这是一个带有提示信息的链接"&gt;点击这里 ``` 当用户将鼠标悬停在链接上时,浏览器会显示"这是一个带...

    操作浏览器标题栏插件Title.js

    5. **恢复原状**:若需恢复到初始标题,可以使用 `Title.reset()` 方法: ```javascript Title.reset(); ``` Title.js 的强大之处在于它的灵活性和易用性,开发者可以根据需求自由定制标题更新的行为。通过结合各种...

    javascript经典特效---Title特效.rar

    需要注意的是,虽然Title特效可以增加网站的吸引力,但过度使用或不恰当的使用可能会对用户体验造成负面影响。因此,设计Title特效时应考虑其适用性和用户体验,避免过于花哨或分散用户注意力。 总的来说,...

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

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

    easyui利用tooltip实现title功能

    在IT领域,特别是前端开发中,使用EasyUI框架来增强用户界面的功能性和美观性是一种常见的实践。EasyUI是一个基于jQuery的UI工具包,它提供了一系列的用户界面组件,如按钮、对话框、网格等,使得开发者能够快速地...

    设置网页元素 提示信息 如title,alt提示

    在代码中,我们可能会看到这样的用法: ```html &lt;a href="https://www.example.com" title="访问示例网站"&gt;点击这里 ``` 当鼠标停留在链接上时,"访问示例网站"会作为提示信息显示出来。默认情况下,这个提示信息...

    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

    很好,很强大的title弹出提示

    "很好,很强大的title弹出提示"这个标题暗示了我们即将探讨一个能够增强网页提示功能的方法,即利用sweet-titles-for-jquery插件。这个插件允许开发者为网页元素添加动态、美观的title提示效果,以更吸引人的形式...

    Laravel开发-pagetitle

    然而,这种方法对于大型项目来说并不理想,因为每个视图都需要独立维护标题,容易导致代码重复且不易维护。 为了解决这个问题,我们可以创建一个全局的帮助器函数或者使用View Composer来集中管理页面标题。以下是...

    ActionBar Title文字居中

    -- 如果使用的是AndroidX库,则使用以下代码 --&gt; &lt;!-- &lt;item name="titleTextStyle"&gt;@style/CenteredTitleStyle&lt;/item&gt; --&gt; ``` 2. **定义标题样式**: 接下来,我们需要创建一个自定义的标题样式`...

    title及alt提示个性化特效

    这个“title及alt提示个性化特效”可能包含了一种使用JavaScript来增强这两种属性表现方式的方法。JavaScript是一种强大的客户端脚本语言,可以在用户与网页交互时动态改变网页内容。通过JavaScript,开发者可以实现...

    基本jquery title显示插件 tipTipv13

    下面我们将深入探讨这个插件的基本原理、使用方法以及它的核心特性。 一、jQuery TipTipv13简介 TipTipv13是基于jQuery库的一个插件,它的主要功能是将HTML元素的`title`属性内容以更美观、可定制的方式展现出来,...

Global site tag (gtag.js) - Google Analytics