jQuery toggleClass(樣本1)

來源:互聯網
上載者:User

1、首先到jQuery官網下載js庫,網址為http://jquery.com/

2、建立一個jQuery樣本的項目。

3、將js庫放到jQuery樣本的項目中。

4、寫一個html頁面

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<meta http-equiv="author" content="Kong.Yee"/>
<meta http-equiv="corporation" content="廣州匡興軟體科技有限公司"/>
<meta http-equiv="contact" content="791663094或kong.yee@foxmail.com"/>
<script type="text/javascript" language="JavaScript" src="js/jquery-1.10.2.js"></script>
<title>Insert title here</title>
<style type="text/css">
.bg{
/*背景顏色*/
background: #f00;
/*字型顏色*/
color: #fff;
width: 80px;
}

ul, li {
/*清除ul和li上預設的小圓點*/
list-style: none;
}

ul {
/*清除子功能表的縮排值*/
padding: 0;/*IE8,IE9,Firefox可以;IE7,IE6,IE5.5不行*/
margin: 0;/*都可以了*/
}

</style>
<script type="text/javascript">
$(function(){
//setColor是滑鼠移動的方法
$("li").mouseover(setColor).mouseout(setColor);

function setColor(){
//如果存在(不存在)就刪除(添加)一個類
$(this).toggleClass("bg");
}
});
</script>
</head>
<body>
<div id="div">
<ul>
<li>橫向菜單1</li>
<li>橫向菜單2</li>
<li>橫向菜單3</li>
<li>橫向菜單4</li>
<li>橫向菜單5</li>
<li>橫向菜單6</li>
</ul>
</div>
</body>
</html>

5、運行



備忘
*技術交流與合作:QQ: 791663094;Email:kong.yee@foxmail.com

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.