首页> 基础笔记 >JS/JQ基础学习 >事件 事件

JavaScript-双击事件ondblclick

作者:小萝卜 2023-03-22 浏览 310

简介JavaScript-双击事件ondblclick

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>双击事件</title>
</head>
<body>
	<div id="move" style="width:200px;height:200px;background:#456"></div>
	<script type="text/javascript">
	//
	var move = document.getElementById('move');
	//
	move.ondblclick = function(){
		//获取元素原来的宽度
		var w = parseInt(this.style.width);//200
		//数据类型转换
		var newW = w+5;

		var r = rand(0,255);
		var g = rand(0,255);
		var b = rand(0,255);
		this.style.background = "rgb("+r+","+g+","+b+")";
		this.style.width = newW+'px';
	}

	function rand(m,n){
		return Math.ceil(Math.random()*(n-m+1))+m-1;
	}

	</script>
</body>
</html>
 

很赞哦! (0)

文章评论

    高端网站建设