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 456">text</div>
<div title="123& #10;456">text</div>
<a href="" title="怎样强 制换行">留言</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 
 (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...
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值