开始学习jQuery和准备工做

<script>
$(document).ready(function(){

});css

首先,在页面顶部添加一行script元素,而后在下一行写上结束符。html

浏览器会运行script里全部的Javascript,包括jQuery。浏览器

在你的script元素里,添加这段代码:$(document).ready(function() {到你的script中,而后在下一行用});结束它。app


使用jQuery选择器操做同一元素

<script>
$(document).ready(function() {
$("button").addClass("animated");
$(".btn").addClass("shake");
$("#target1").addClass("btn-primary");//首选项
});
</script>spa

使用jQuery改变HTML元素的CSS样式

$("#target1").css("color", "blue");code

使用jQuery设置元素不可用

$("button").prop("disabled", true);htm

使用jQuery改变元素中的文本

$("h3").html("<em>jQuery Playground</em>");索引

使用jQuery删除一个HTML元素

 $("#target4").remove();ip

jQuery使用appendTo()移动HTML元素

$("#target4").appendTo("#left-well");rem

jQuery使用clone()方法复制元素

$("#target2").clone().appendTo("#right-well");//两个jQuery方法合在一块儿使用了?这种叫方法链function chaining

target2left-well复制到right-well

jQuery使用parent()操做父级元素

$("#left-well").parent().css("background-color", "blue")

jQuery使用children()操做子级元素

$("#left-well").children().css("color", "blue")

 

jQuery使用target:nth-child(n) CSS选择器获取子元素

$(".target:nth-child(3)").addClass("animated bounce");

//如下代码显示如何给jQuery Playground中的每一个井中(left well和right well)的第三个子元素添加bounce类:

jQuery使用选择器操做偶数索引元素

$(".target:even").addClass("animated shake"); //偶数

$(".target:odd").addClass("animated shake");//奇数

使用jQuery修改整个页面

$("body").addClass("animated fadeOut");//整个body有淡出效果

$("body").addClass("animated hinge");//一左上角为圆心 顺时针晃动 下坠淡出

相关文章
相关标签/搜索