第一课:初始JavaScript

本文介绍如何使用HTML、CSS及JavaScript实现一个简单的鼠标提示框效果。当鼠标悬停在输入框上时,提示信息会以div的形式显示;鼠标离开时,提示信息消失。此外,还展示了如何改变div的样式。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

HTML+CSS静态网页
js     交互、功能

第一个js效果---鼠标提示框

鼠标移入到input上的时候,让div显示
鼠标移除input让div隐藏

div1显示: block

----------------------------------

事件

onclick

----------------------------------

div1.style.display='block'
.     的
div1的style的display
=     赋值
document.getElementById


兼容性问题
chrome
ff

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<style>
#div1{width:200px;height:100px; border:1px solid #999; background-color:#CCC;
	display:none;}
</style>
</head>
<body>
<!--注释 -->
<input type="checkbox" onmouseover="document.getElementById('div1').style.display='block'" 
onmouseout="document.getElementById('div1').style.display='none'"/>
<div id="div1" >
为了您的信息安全
</div>
</body>
</html>


=======================================
get Element By Id    通过id获取元素
获取 元素   用  id


--------------------------------
属性 
特性 特点


blue.名字 blue
blue.性别 男
blue.身高  173


-----------------------------------

重用

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<style>
#div1{width:200px; height:200px; background:red;}
</style>
<script>
function toGreen(){
	var odiv = document.getElementById('div1');
	document.getElementById('div1').style.width='300px';
	document.getElementById('div1').style.height='300px';
	document.getElementById('div1').style.background='green';
	}
function toRed(){
	document.getElementById('div1').style.width='200px';
	document.getElementById('div1').style.height='200px';
	document.getElementById('div1').style.background='red';
	}
</script>
</head>

<body>
<div id="div1" onmouseover="toGreen()" onmouseout="toRed()">
</div>
</body>
</html>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值