jQuery相关方法1
一、设置某个元素的标签内容------.html()方法
<script src="http://libs.baidu.com/jquery/1.10.2/jquery.min.js"></script>
<script>
//1.jQuery对象.val()--------获取或者设置表单标签的value属性值
//2.jQuery对象.text()--------获取或者设置标签的文本内容----相当于DOM的innerText
//3.jQuery对象.css()--------获取或者设置css的样式属性值
//4.jQuery对象.html()--------获取或者设置标签中的HTML内容----相当于DOM中的innerHTML
$(function(){
$("#btn").click(function () {
$("#dv").html("<p>这是一个p标签</p>")
});
});
</script>
<input type="button" value="设置" id="btn">
<div id="dv">我是div</div>
二、设置元素的样式-------.css()方法
<script src="http://libs.baidu.com/jquery/1.10.2/jquery.min.js"></script>
<script>
//点击按钮,设置div的宽,高,背景颜色,边框
$(function(){
$("#btn").click(function(){
$("#dv").css("width","300px");
$("#dv").css("height","300px");
$("#dv").css("backgroundColor","red");
$("#dv").css("border","3px solid blue");
});
});
</script>
<input type="button" value="设置" id="btn">
<div id="dv"></div>
三、案例:列表隔行变色效果------even和odd
<script src="http://libs.baidu.com/jquery/1.10.2/jquery.min.js"></script>
<script>
//注意:
//对象:odd----奇数的
//对象:even----偶数的
$(function(){
$("#btn").click(function () {
$("#uu>li:even").css("backgroundColor","red");
$("#uu>li:odd").css("backgroundColor","yellow");
});
});
</script>
<input type="button" value="设置" id="btn">
<ul id="uu">
<li>隔行变色</li>
<li>隔行变色</li>
<li>隔行变色</li>
<li>隔行变色</li>
<li>隔行变色</li>
</ul>
四、案例:显示和隐藏下拉菜单效果----.mouseenter()和.mouseleave()和.show()和.hide()和.stop()方法
<style>
li{
list-style: none;
}
.wrap>ul>li{
float: left;
height: 100px;
width: 100px;
}
.wrap>ul>li:first-child ul{
background: red;
display: none;
}
.wrap>ul>li:nth-child(2) ul{
background: yellow;
display: none;
}
.wrap>ul>li:last-child ul{
background: blue;
display: none;
}
</style>
<script src="http://libs.baidu.com/jquery/1.10.2/jquery.min.js"></script>
<script>
//鼠标进入事件-----对象.mouseenter()
//鼠标离开事件-----对象.mouseleave()
//对象.show()方法-------动画出现效果
//对象.hide()方法-------动画消失效果
//对象.stop()方法----用于停止动画或效果,在它们完成之前。
$(function(){
//获取ul中的所有的li,注册鼠标进入和鼠标离开事件
$(".wrap>ul>li").mouseenter(function(){
//当前的li中所有的子元素,再从所有的子元素中找到ul
$(this).children("ul").stop().show(200);
});
$(".wrap>ul>li").mouseleave(function(){
$(this).children("ul").stop().hide(200);
});
});
</script>
<div class="wrap">
<ul>
<li>
<a href="javascript:void(0);">红色系列</a>
<ul>
<li><a href="javascript:void(0);">红色1</a></li>
<li><a href="javascript:void(0);">红色2</a></li>
<li><a href="javascript:void(0);">红色3</a></li>
</ul>
</li>
<li>
<a href="javascript:void(0);">黄色系列</a>
<ul>
<li><a href="javascript:void(0);">黄色1</a></li>
<li><a href="javascript:void(0);">黄色2</a></li>
<li><a href="javascript:void(0);">黄色3</a></li>
</ul>
</li>
<li>
<a href="javascript:void(0);">蓝色系列</a>
<ul>
<li><a href="javascript:void(0);">蓝色1</a></li>
<li><a href="javascript:void(0);">蓝色2</a></li>
<li><a href="javascript:void(0);">蓝色3</a></li>
</ul>
</li>
</ul>
</div>

五、案例:列表的高亮显示效果
<script src="http://libs.baidu.com/jquery/1.10.2/jquery.min.js"></script>
<script>
$(function(){
//鼠标进入事件
$("#uu>li").mouseenter(function(){
$(this).css("backgroundColor","red");
});
//鼠标离开事件
$("#uu>li").mouseleave(function(){
$(this).css("backgroundColor","");
});
//点击事件
$("#uu>li").click(function(){
$(this).css("color","green");
$(this).css("fontSize","30px");
$(this).css("fontFamily","微软雅黑");
});
});
</script>
<ul id="uu">
<li>李白</li>
<li>杜甫</li>
<li>孟浩然</li>
<li>李清照</li>
<li>杜牧</li>
</ul>

六、案例:验证中文名字
<script src="http://libs.baidu.com/jquery/1.10.2/jquery.min.js"></script>
<script>
$(function(){
//按钮的点击事件
$("#btn").click(function(){
if(/^[\u4e00-\u9fa5]{2,6}$/.test($("#txt").val())){
$("#txt").css("backgroundColor","red");
}else{
$("#txt").css("backgroundColor","yellow");
}
});
});
</script>
请输入中文名字:<input type="text" value="" id="txt">
<input type="button" value="验证" id="btn">

七、案例:淘宝精品展示效果
<style>
#left,#center,#right{
float: left;
}
li{
list-style: none;
}
a{
text-decoration: none;
}
#left li{
width: 50px;
height: 25px;
border: 1px solid #000;
}
#center li{
width: 200px;
height: 200px;
display: none;
}
#right li{
width: 50px;
height: 25px;
border: 1px solid #000;
}
</style>
<script src="http://libs.baidu.com/jquery/1.10.2/jquery.min.js"></script>
<script>
$(function(){
//左边的
$("#left>li").mouseenter(function(){
var index=$(this).index();
$("#center>li").hide();
$("#center>li:eq("+index+")").show();
});
//右边的
$("#right>li").mouseenter(function(){
var index=$(this).index()+5;
$("#center>li").hide();
$("#center>li:eq("+index+")").show();
});
});
</script>
<div class="wrapper">
<ul id="left">
<li><a href="#">曹操</a></li>
<li><a href="#">许褚</a></li>
<li><a href="#">典韦</a></li>
<li><a href="#">夏侯惇</a></li>
<li><a href="#">张辽</a></li>
</ul>
<ul id="center">
<li style="background: red;display: block;"></li>
<li style="background: blue;"></li>
<li style="background: white;"></li>
<li style="background: black;"></li>
<li style="background: pink;"></li>
<li style="background: green;"></li>
<li style="background: yellow;"></li>
<li style="background: grey;"></li>
<li style="background: orange;"></li>
<li style="background: purple;"></li>
</ul>
<ul id="right">
<li><a href="#">刘备</a></li>
<li><a href="#">关羽</a></li>
<li><a href="#">张飞</a></li>
<li><a href="#">赵云</a></li>
<li><a href="#">黄忠</a></li>
</ul>
</div>

jQuery相关方法1的更多相关文章
- jQuery相关方法2
一.元素样式设置的方式(css,json键值对,链式编程) <script src="http://libs.baidu.com/jquery/1.10.2/jquery.min.js ...
- jQuery相关方法10
一.链式编程的原理 <script> //构造函数 function Person(age){ this.age=age; this.sayHi=function(txt){ if(txt ...
- jQuery相关方法9----事件相关
一.事件冒泡和阻止事件冒泡 <script src="http://libs.baidu.com/jquery/1.10.2/jquery.min.js"></s ...
- jQuery相关方法8-----解绑事件
一.解绑事件方法unbind() 用什么方式绑定的事件,最好用对应的方式解绑事件 unbind("事件名字")括号里写上事件名字,就会解除这个事件 unbind()括号里没有参数就 ...
- jQuery相关方法7----各种事件和绑定事件
一.jQuery事件 1.鼠标事件 click与dbclick事件 click事件其实是由mousedown与mouseup 2个动作构成,所以点击的动作只有在松手后才触发 $ele.click(): ...
- jQuery相关方法6----三大系列属性
一.获取和设置元素的宽和高------width( )方法和height()方法 <!-- 点击按钮,设置div的宽和高为原来的两倍 --> <script src="ht ...
- jQuery相关方法5----表单相关
一.value属性在表单的相关操作-----val()方法 <script src="http://libs.baidu.com/jquery/1.10.2/jquery.min.js ...
- jQuery相关方法4-----元素创建和移除
一.创建添加元素 父元素.append(子元素)-----被动追加创建 子元素.appendTo(父元素)-----主动追加创建 <script src="http://libs.ba ...
- jQuery相关方法3----动画相关
一.显示和隐藏 show(参数1,参数2)方法和hide(参数1,参数2)方法,动画效果显示和隐藏 参数1是时间,单位毫秒(1000毫秒=1秒),也可以是 "slow"" ...
随机推荐
- go context 源码分析
WithCancel func WithCancel(parent Context) (ctx Context, cancel CancelFunc) { c := newCancelCtx(pare ...
- 12.Scratch编程小游戏——天上掉馅饼
最意想天开的事,就是天降我们喜欢的食物,今天我们就来编写一个接馅饼的小游戏. 游戏规划: 1.用鼠标控制小猫的来回移动 2.甜甜圈从天而降 3.小猫接到绿色的甜甜圈减一分,接到红色的甜甜圈加一分,接到 ...
- MySQL 5.7使用xtabackup报错解决
报错信息: InnoDB: An optimized (without redo logging) DDLoperation has been performed. All modified page ...
- Spring Cloud Alibaba学习笔记(4) - Feign配置与使用
什么是Feign Feign是一个声明式Web Service客户端. 使用Feign能让编写Web Service客户端更加简单, 它的使用方法是定义一个接口,然后在上面添加注解,同时也支持JAX- ...
- git clone github上的项目失败 RPC failed
error: RPC failed; curl 18 transfer closed with outstanding read data remainingfatal: the remote end ...
- List<T> or IList<T>
If you are exposing your class through a library that others will use, you generally want to expos ...
- JS定时器做物体运动
JS定时器是函数 setInterval(函数体/函数名 , 时间) 清楚定时器 clearInterval(函数) 时间单位(毫秒) 1000毫秒 = 1秒 首先我们要知道用JS定时器能干什么? ...
- K2 BPM_康熙别烦恼(下篇)——审批矩阵_工作流引擎
康熙别烦恼(上篇)——分级授权 End 公司介绍:上海斯歌信息技术有限公司,聚焦企业所关注的管理挑战和压力,提供BPM平台及相关解决方案为主.2005年正式进入大中华地区,总部设在上海,并在北京.深圳 ...
- java.sql.Date和java.sql.Timestamp转换
转自:https://www.xuebuyuan.com/1479399.html 在开发web应用中,针对不同的数据库日期类型,我们需要在我们的程序中对日期类型做各种不同的转换.若对应数据库数据是o ...
- springboot 日志配置
maven依赖中添加了 spring-boot-starter-logging : <dependency> <groupId>org.springframework.boot ...