加入收藏 | 设为首页 | 会员中心 | 我要投稿 湖南网 (https://www.hunanwang.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 业界 > 正文

jQuery 实现持续列表结果

发布时间:2018-08-18 10:13:44 所属栏目:业界 来源:站长网
导读:你有没有手工的编写过一些一再的代码?你也认为它们是云云的无聊吧。好了,这里有更好的办理步伐。这个教程将汇报你怎样运用 jQuery 添加持续的CSS类天生一个活跃的列表。第二个示例是怎样运用jQuery的prepend特征为留言列表添加一个留言计数。 可以先看看

下载jQuery,在<head>标签之间如下添加jQuery代码:

Copy to ClipboardLiehuo.Net Codes引用的内容:[www.veryhuo.com] <script type="text/javascript" src="jquery.js"></script>

<script type="text/javascript">
$(document).ready(function(){

$("#step li").each(function (i) {
i = i+1;
$(this).addClass("item" i);
});

});
</script>

jQuery将如下输出html源码:

list-output-code

1b.CSS编码

响应的运用配景图片样式化<li>元素。(step1.png, step2.png, step3.png等等)。

Copy to ClipboardLiehuo.Net Codes引用的内容:[www.veryhuo.com] #step .item1 {
background: url(step1.png) no-repeat;
}
#step .item2 {
background: url(step2.png) no-repeat;
}
#step .item3 {
background: url(step3.png) no-repeat;
}

step-list

2a.添加持续的内容

你也可以运用这种能力添加有序的内容,运用jQuery的prepend要领。下面就回收此种要领天生存数的留言列表。

Copy to ClipboardLiehuo.Net Codes引用的内容:[www.veryhuo.com] <script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
$(document).ready(function(){

$("#commentlist li").each(function (i) {
i = i+1;
$(this).prepend('<span class="commentnumber"> #' i '</span>');
});

});
</script>

将为每个<li>添加一个<span calss=”commentnumber”>计数</span>.

commentlist-output-code

2b.CSS

样式化<li>:position:relative 用position:absolute把.commentnumber放在留言条目标右上角。

commentlist-counter

英文原文:web designer wall 翻译:http://www.cnblogs.com/island205/

(编辑:湖南网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

热点阅读