html怎么实现鼠标放在文字上显示文字(附带代码)?

html-css09

html怎么实现鼠标放在文字上显示文字(附带代码)?,第1张

实现鼠标悬停显示文字,html中使用title属性就可实现显示文字的效果,这个属性还是比较实用的,你可以参考下

<a href="#" title="这里是显示的文字">hello</a>

当鼠标悬停在 hello上一会就会有文字 "这里是显示的文字" 显示。

需要准备的材料分别有:电脑、浏览器、html编辑器。

1、首先,打开html编辑器,新建html文件,例如:index.html。

2、在index.html中的<script>标签中,输入js代码:

$('button').click(function () {$('div').css('display', 'block')})

3、浏览器运行index.html页面,会有个显示按钮。

4、点击显示按钮,此时被隐藏的内容显示了出来。

<!DOCTYPE html>

<html>

<head>

<meta charset="UTF-8">

<title></title>

<style type="text/css">

body {

margin: 0

padding: 0

}

#hide {

display: none

}

</style>

<script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>

<script type="text/javascript">

$(function() {

$('#btn1').click(function() {

$('#hide').show()

var t = setTimeout("$('#hide').hide()", 5000)

})

var html = ''

$('#btn2').click(function(){

    html += '<div>生成的文字(5S后消失)</div>'

$('#apd').append(html)

var t = setTimeout("$('#apd').text('')", 5000)

html = ''

})

})

</script>

</head>

<body>

<div id="box1">

<button id="btn1">点击显示隐藏文字</button>

<div id="hide">

显示隐藏的文字(5S后消失)

</div>

</div>

<div id="box2">

<button id="btn2">点击生成文字</button>

<div id="apd">

</div>

</div>

</body>

</html>