国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > JavaScript > 正文

JQuery控制DIV的選取實現方法

2019-11-20 08:57:33
字體:
來源:轉載
供稿:網友

我們設置4個div 當鼠標移動到某一個div上面的時候 背景顏色就會發生變化

那我們應該知道要用到mouseover() 和 mouseout() 前一個是移動到某個位置 后面是移開某個位置

還有一個hover(,) 可以替代上面兩個方法

1.用mouseover()和mouseout()

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><script type="text/javascript" src="jQuery/jquery-1.12.1.js"></script><script type="text/javascript">$(function(){	$("div[id^='div']").mouseover(function() {    $(this).css("background-color","red");    //$(this).css({"background-color":"red"}); });	$("div[id^='div']").mouseout(function() {    $(this).css("background-color","#0FC");    //$(this).css({"background-color":"#0FC"}); });});</script><style type="text/css">div[id^="div"]{	width:300px;	height:500px;	background-color:#0FC;	border:1px solid black;	float:left;	margin-left:2px;}</style></head><body><div id="div1"></div><div id="div2"></div><div id="div3"></div><div id="div4"></div></body></html>

2.hover()

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><script type="text/javascript" src="jQuery/jquery-1.12.1.js"></script><script type="text/javascript">$(function(){	$("div[id^='div']").hover(function(){		$(this).css("background-color","blue");		},		function(){			$(this).css("background-color","#0FC");	});});</script><style type="text/css">div[id^="div"]{	width:300px;	height:500px;	background-color:#0FC;	border:1px solid black;	float:left;	margin-left:2px;}</style></head><body><div id="div1"></div><div id="div2"></div><div id="div3"></div><div id="div4"></div></body></html>

也可以這么寫

$(function(){	var In = function(){		$(this).css("background-color","red");	}	var Out = function(){		$(this).css("background-color","yellow");	}			$("p[id^='p']").hover(In,Out);	});

以上這篇JQuery控制DIV的選取實現方法就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支持武林網。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 焉耆| 望奎县| 额敏县| 桑日县| 芦溪县| 视频| 江达县| 长海县| 富裕县| 静宁县| 汽车| 萨嘎县| 开江县| 云和县| 库伦旗| 冀州市| 怀宁县| 彩票| 重庆市| 夹江县| 宁海县| 遂溪县| 贺兰县| 兰坪| 扶绥县| 琼结县| 禹州市| 莱州市| 建昌县| 德惠市| 巩留县| 南乐县| 图片| 郴州市| 河曲县| 那坡县| 西畴县| 霍林郭勒市| 广昌县| 南平市| 扬州市|