前端学习——jquery操作例子
一、jquery和DOM函数的转换
、 jquery转换成dom
$('#i1') --------------> $('#i1')[]
、 dom转换成jquery
var i1=documen.getElementById('#i1')---------> $(i1)
二、写左侧菜单
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
.header{
cursor: pointer;
background-color: #2459a2;
width:300px;
color: white;
}
.hide{
display: none;
}
</style>
</head>
<body> <div>
<div class="header">菜单一</div>
<div class="content">
<div>内容一</div>
<div>内容一</div>
</div> <div class="header">菜单二</div>
<div class="content hide">
<div>内容二</div>
<div>内容二</div>
</div> <div class="header">菜单三</div>
<div class="content hide">
<div>内容三</div>
<div>内容三</div>
</div>
</div> <script src="jquery.js"></script>
<script> $('.header').click(function(){
// jQuery链式编程
$(this).siblings('.content').toggleClass('hide');
// $(this).next().removeClass('hide');
}); </script>
</body>
</html>
addClass(“className”)方法是用来给指定元素增加类名,也就是说给指定的元素追加样式;
.removeClass(“className”)方法是用来给指定的元素移除类名,也就是说给指定元素移除样式;
.toggleClass(“className”)方法是用来给脂定的元素增加或移除类名(如果元素的类名存在就移除,如果不存在就增加),也就是说用来给指定的元素进行样式切换(如果元素存在样式则去掉,如果不存在则加上样式)
三、jquery实现模态框
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
.fluid{
position: absolute;
top:;
left:;
right:;
bottom:;
background-color: black;
opacity: 0.5;
}
.modal{
position: absolute;
top:%;
left:%;
background-color: white;
width:300px;
height:200px;
}
.hide{
display: none;
}
</style>
</head>
<body> <input type="button" value="添加" /> <table border="1px">
<tr>
<th>IP</th>
<th>端口</th>
<th>操作</th>
</tr>
<tr>
<td>1.1.1.1</td>
<td></td>
<td>
<input type="button" value="编辑" class="edit"> </td>
</tr>
<tr>
<td>2.2.2.2</td>
<td></td>
<td><input type="button" value="编辑" class="edit"></td>
</tr>
<tr>
<td>3.3.3.3</td>
<td></td>
<td><input type="button" value="编辑" class="edit"></td>
</tr>
</table> <!--遮罩层-->
<div class="fluid hide"> </div> <div class="modal hide">
<p>
IP: <input type="text" name="ip" id="ip">
</p>
<p>
端口: <input type="text" name="port" id="port">
</p>
<p><input type="button" value="ok"><input type="button" value="cancel" id="cancel"></p>
</div> <script src="jquery.js"></script> <script>
$('.edit').click(function(){
$(".fluid").removeClass('hide');
$(".modal").removeClass('hide'); var tds = $(this).parent().prevAll();
// console.log(tds[0].innerText);
$("#port").val(tds[].innerText);
$("#ip").val(tds[].innerText); }); $("#cancel").click(function(){
$(".fluid").addClass('hide');
$(".modal").addClass('hide');
}); </script> </body>
</html>
四、互相选择框,单选及多选到目的框
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
div{
float: left;
margin-left: 20px;
}
select{
width:200px;
}
</style>
</head>
<body> <div>
<select name="fruit" id="fruit" multiple>
<option value="">香蕉</option>
<option value="">苹果</option>
<option value="">橘子</option>
<option value="">菠萝</option>
</select>
</div> <div>
<input type="button" value="=>" id="toRight"><br>
<input type="button" value="==>" id="toAllRight">
</div> <div>
<select name="shuiguo" id="shuiguo" multiple> </select>
</div> <script src="jquery.js"></script> <script>
$("#toRight").click(function () {
$("#fruit option:checked").clone().appendTo("#shuiguo");
// $("#shuiguo").append($("#fruit option:checked"));
}); $("#toAllRight").click(function () {
$("#fruit option").clone().appendTo("#shuiguo");
})
</script> </body>
</html>
五、酒仙网动画实例-采用animate
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
.wine{
width:180px;
overflow: hidden;
} </style>
<script src="jquery.js"></script> </head>
<body> <div class="wine">
<img src="wine.jpg" alt="">
</div> <div class="wine">
<img src="wine.jpg" alt="">
</div>
<div class="wine">
<img src="wine.jpg" alt="">
</div><div class="wine">
<img src="wine.jpg" alt="">
</div><div class="wine">
<img src="wine.jpg" alt="">
</div> <script>
$(function(){ $("img").hover(
function () {
$(this).animate({"margin-left":"-100px"},);
},
function (){
$(this).animate({"margin-left":""},)
}
); }); </script>
</body>
</html>
前端学习——jquery操作例子的更多相关文章
- 前端学习——JQuery Ajax使用经验
0.前言 在项目推进过程中常常使用Ajax,通过Jquery提供的函数能够很方便的使用Ajax,可是在实际使用中也遇到一些问题,比如怎样防止浏览器使用缓存,怎样使用同步方式等.通过博文整理总结 ...
- 前端学习☞jquery
一 什么是jQuery对象? jQuery 对象就是通过jQuery包装DOM对象后产生的对象.jQuery 对象是 jQuery 独有的. 如果一个对象是 jQuery 对象, 那么它就可以使用 j ...
- 前端学习-jQuery
老师博客:https://www.cnblogs.com/yuanchenqi/articles/6070667.html day43,day44 jquery 中文文档:http://jquery. ...
- 前端学习——使用Ajax方式POST JSON数据包
0.前言 本文解释怎样使用Jquery中的ajax方法传递JSON数据包,传递的方法使用POST(当然PUT又有时也是一个不错的选择).POST JSON数据包相比标准的POST格式可读性更好 ...
- 前端学习之jquery/下
前端学习之jquery 一 属性操作 html(): console.log($("div").html()); $(".test").html("& ...
- 前端学习之jquery
前端学习之jquery 1. 什么是jQuery对象? jQuery对象就是通过jQuery包装DOM对象后产生的对象.jQuery对象是jQuery独有的.如果一个对象是jQuery对象,那么它 ...
- Jquery重新学习之五[操作JSON数据]
Jquery操作Json格式的数据在我们平时的项目中也经常运用:最近看Jquery权威指南中就有一章节是对这方面的整理总结:最后通过一个Asp.net结合一般处理程序ashx的实例,基本上能满足项目中 ...
- jQuery操作标签,jQuery事件操作,jQuery动画效果,前端框架
jQuery操作标签 jQuery代码查找标签绑定的变量名推荐使用 $xxxEle 样式类操作 addClass();// 添加指定的CSS类名. removeClass();// 移除指定的CSS类 ...
- 从零开始学习jQuery (四) 使用jQuery操作元素的属性与样式
本系列文章导航 从零开始学习jQuery (四) 使用jQuery操作元素的属性与样式 一.摘要 本篇文章讲解如何使用jQuery获取和操作元素的属性和CSS样式. 其中DOM属性和元素属性的区分值得 ...
随机推荐
- 如何给wpf的按钮添加背景图片
1:简单实用 <Button Height="143" HorizontalAlignment="Left" Margin="30,34,0,0 ...
- Confluence 6 使用 LDAP 授权连接一个内部目录 - 高级设置
ted Groups 为嵌套组启用或禁用支持. 一些目录服务器能够允许你在一个组中定义另外一个组.在这种结构下的用户组称为用户组嵌套.嵌套组的配置能够让子用户组继承上级用户组的权限,是系统的权限配置变 ...
- 『cs231n』作业3问题3选讲_通过代码理解图像梯度
Saliency Maps 这部分想探究一下 CNN 内部的原理,参考论文 Deep Inside Convolutional Networks: Visualising Image Classifi ...
- ubuntu64位库
安装 12.04ubuntu32位库:sudo apt-get install ia32-libs
- 时间序列预测——深度好文,ARIMA是最难用的(数据预处理过程不适合工业应用),线性回归模型简单适用,预测趋势很不错,xgboost的话,不太适合趋势预测,如果数据平稳也可以使用。
补充:https://bmcbioinformatics.biomedcentral.com/articles/10.1186/1471-2105-15-276 如果用arima的话,还不如使用随机森 ...
- ES批量索引写入时的ID自动生成算法
对bulk request的处理流程: 1.遍历所有的request,对其做一些加工,主要包括:获取routing(如果mapping里有的话).指定的timestamp(如果没有带timestamp ...
- SQL Server 调优系列基础篇 - 联合运算符总
前言 上两篇文章我们介绍了查看查询计划的方式,以及一些常用的连接运算符的优化技巧,本篇我们总结联合运算符的使用方式和优化技巧. 废话少说,直接进入本篇的主题. 技术准备 基于SQL Server200 ...
- hdu3874
题解: 和上一题基本相同 插入的时候变一下数值 具体看http://www.cnblogs.com/xuanyiming/p/7921926.html 代码: #include<cstdio&g ...
- 【转】Linux编程之UDP SOCKET全攻略
转自:http://www.cnblogs.com/skyfsm/p/6287787.html?utm_source=itdadao&utm_medium=referral 这篇文章将对lin ...
- python metaclass
看了很多类似的博客,这篇算是写的比较完善的,转载以备后期查看 原文: 一 你可以从这里获取什么? 1. 也许你在阅读别人的代码的时候碰到过metaclass,那你可以参考这里的介绍. 2. 或许你需要 ...