准备
- 语法如下<script>$(document).ready(function(){});</script>
jQuery 使用选择器获取 html 元素
- 添加按钮回弹效果$("button")来选中按钮用.addClass("animated bounce")给按钮加CSS class。 < script > $(document).ready(function() {
- $("button").addClass("animated bounce");
- }); < /script>/
jQuery 使用 addClass() 方法给元素加 class
$(".well").addClass("animated shake");
jQuery 根据 id 属性来获取元素
渐变隐藏效果 $("#target3").addClass("animated fadeOut");
三种选择器
元素选择器:$("button") class 选择器:$(".btn") id 选择器:$("#target1")
使用 jQUery 删除 HTML 元素的 class
$("#target2").removeClass("btn-default");
使用 jQUery 改变 HTML 元素的 css 样式
选择器. css("属性","值"); $("#target1").css("color","red");
使用 jQUery 设置元素不可用
$("#target1").prop("disabled",true);
jQuery 使用 text() 改变文本内容
[emphasize] 标签来重写和强调标题文本 .text() 它只能改变文本但不能修改标记 $("#target4").html("");
使用 jQuery 删除一个 html 元素
$(#target4).remove();
jQuery 使用 appendTo() 移动 html 元素
把元素从一个 div 里移到另外一个 div 里 $("#target2").appendTo("#right-well");
jQuery 使用 clone() 方法拷贝元素
移动元素就是剪切,拷贝元素就是复制, 所以应该就是 clone 一个,然后移动过去。 $("#target5").clone().appendTo("#left-well");
jQuery 使用 parent() 操作父级元素
$("#target1").parent().css("background-color","red");
jQuery 使用 children() 操作子级元素
$("#right-well").children().css("color","orange");
jQuery 使用 target:nth-child(n) CSS 选择器索引操作元素
:nth-child() 按照
顺序索引是从 1 开始的 $(".target:nth-child(2)").addClass("animated bounce");
jQuery 使用选择器操作 j 索引元素
jQuery 里的索引是从 0 开始的 $(".target:even").addClass("animated shake"); $(".target:odd").addClass("animated shake");
使用 jQuery 修改整个页面
$("body").addClass("animated hinge"); $("body").addClass("animated fadeOut"); 就爱阅读 www.92to.com 网友整理上传, 为您提供最全的知识大全, 期待您的分享,转载请注明出处。
来源: http://www.92to.com/bangong/2017/02-24/17500486.html