1.html()取出或設(shè)置html內(nèi)容
成都創(chuàng)新互聯(lián)致力于互聯(lián)網(wǎng)品牌建設(shè)與網(wǎng)絡(luò)營銷,包括成都做網(wǎng)站、成都網(wǎng)站設(shè)計、SEO優(yōu)化、網(wǎng)絡(luò)推廣、整站優(yōu)化營銷策劃推廣、電子商務(wù)、移動互聯(lián)網(wǎng)營銷等。成都創(chuàng)新互聯(lián)為不同類型的客戶提供良好的互聯(lián)網(wǎng)應(yīng)用定制及解決方案,成都創(chuàng)新互聯(lián)核心團隊10余年專注互聯(lián)網(wǎng)開發(fā),積累了豐富的網(wǎng)站經(jīng)驗,為廣大企業(yè)客戶提供一站式企業(yè)網(wǎng)站建設(shè)服務(wù),在網(wǎng)站建設(shè)行業(yè)內(nèi)樹立了良好口碑。
2.prop()取出或設(shè)置某個屬性的值
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>屬性操作</title>
<script type="text/javascript" src="../jQuery庫/jquery-3.3.1.min.js"></script>
<script type="text/javascript">
$(function(){
var $a = $('.link');
var $img = $('#img');
/*取出某個屬性*/
console.log($a.prop('class'))
/*絕對地址*/
console.log($img.prop('src'));
/*設(shè)置屬性*/
$a.prop({'href':'http://www.baidu.com','title':'百度網(wǎng)'});
/*在標簽內(nèi)寫內(nèi)容*/
$a.html('<em>3</em>');
})
</script>
</head>
<body>
<a href="#" class="link">鏈接</a>
<img src="../../js/images/小林子1.jpg" alt="nanzi" id="img">
</body>
</html>
例子二:手風(fēng)琴
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>手風(fēng)琴</title>
<script type="text/javascript" src="../jQuery庫/jquery-3.3.1.min.js"></script>
<script typt="text/javascript">
$(function(){
var $li = $('.accordion li');
$li.click(function(){
/*點擊的li,左的位置*/
$(this).animate({'left':21*$(this).index()});
/*點擊的li前面元素也跟著左移*/
$(this).prevAll().each(function(){
$(this).animate({'left':21*$(this).index()});
});
/*點擊的li后面的元素左的位置*/
$(this).nextAll().each(function(){
$(this).animate({'left':497-21*(5-$(this).index())});
})
})
})
</script>
<style type="text/css">
.accordion{
width: 497px;
height: 506px;
float: left;
overflow: hidden;
position: relative;
left: 50%;
margin-left: -250px;
}
.accordion ul{
list-style: none;
padding: 0;
}
.accordion ul li{
width: 413px;
height: 506px;
display: inline-block;
float: left;
}
.accordion li span{
display: inline-block;
width: 20px;
height: 506px;
border-bottom: 1px solid #fff;
}
.accordion li img{
display: inline-block;
}
/*位置一*/
.accordion .pick1{
position: absolute;
top: 0;
background-color: #EF4B4E;
}
.accordion .pick1 span{
position: absolute;
top: 0;
}
.accordion .pick1 img{
position: absolute;
top: 0;
left: 21px;
}
/*位置二*/
.accordion .pick2{
position: absolute;
top: 0;
left: 413px;
background-color: #EC3AF1;
}
.accordion .pick2 span{
position: absolute;
top: 0;
}
.accordion .pick2 img{
position: absolute;
left: 21px;
}
/*位置三*/
.accordion .pick3{
position: absolute;
top: 0;
left: 434px;
background-color: #4866F5;
}
.accordion .pick3 span{
position: absolute;
top: 0;
}
.accordion .pick3 img{
position: absolute;
left: 21px;
}
/*位置四*/
.accordion .pick4{
position: absolute;
top: 0;
left: 455px;
background-color: #4DC1F1;
}
.accordion .pick4 span{
position: absolute;
top: 0;
}
.accordion .pick4 img{
position: absolute;
left: 21px;
}
/*位置五*/
.accordion .pick5{
position: absolute;
top: 0;
left: 476px;
background-color: #4CF750;
}
.accordion .pick5 span{
position: absolute;
top: 0;
}
.accordion .pick5 img{
position: absolute;
left: 21px;
}
</style>
</head>
<body>
<div class="accordion">
<ul>
<li class="pick1">
<span>小南子01</span><img src="../../js/images/小林子1.jpg" alt="nanzi">
</li>
<li class="pick2">
<span>小南子02</span><img src="../../js/images/小林子2.png" alt="nanzi">
</li>
<li class="pick3">
<span>小南子03</span><img src="../../js/images/小林子3.png" alt="nanzi">
</li>
<li class="pick4">
<span>小南子04</span><img src="../../js/images/小林子4.png" alt="nanzi">
</li>
<li class="pick5">
<span>小南子05</span><img src="../../js/images/小林子5.png" alt="nanzi">
</li>
</ul>
</div>
</body>
</html>
3.jQuery循環(huán)
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>循環(huán)</title>
<script type="text/javascript" src="../jQuery庫/jquery-3.3.1.min.js"></script>
<script type="text/javascript">
$(function(a){
var $li = $('ul li');
/*循環(huán)each,獲取每一個li*/
$li.each(function(){
if($(this).index()%2==0){
$(this).css({'backgroundColor':'gold'});
}
})
})
</script>
</head>
<body>
<ul>
<li>1</li>
<li>2</li>
<li>3</li>
<li>4</li>
<li>5</li>
<li>6</li>
</ul>
</body>
</html>
當(dāng)前題目:jQuery屬性操作、循環(huán)
本文URL:http://www.rwnh.cn/article8/jipoop.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供虛擬主機、定制網(wǎng)站、動態(tài)網(wǎng)站、網(wǎng)站改版、網(wǎng)站建設(shè)、網(wǎng)站排名
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)