js

一 js引入方式(不可以通过name,来引入)

 方式一:定义一个事件

function a()
{
alert("fdafdasf");
}

方式二:通过id
onload=function()
{
document.getElementById("id1").onclick=function()
{
alert("fdsafdsafa")
}
}

二 js与jq相互转化
jq 的调用方法
$("#id").click(function(){alert("string");});

js的调用方法
document.getElementById("id").onclick=function(){alert("string");}

js与jq混合调用
$(document.getElementById("id").click(function(){alert("string");});

$("#id")[0].onclick=function(){alert("string");};

三 jq选择器
1 标准的 id 类 和标签选择器
2 其他选择器
$("p:odd").css("color","red");偶数行,变为红色
$("p:even").css("color","red");奇数行,变为红色
$("p:first").css("color","red");第一行p标签变色
$("p:fist-child").css("color","red");父亲的第一个p标签变色
$("div.has(a)).css("color","red");里面包含a标签的div变色,是div变色
$("a[href]").css("color","red");含有herf的a标签改变颜色,是a标签改变颜色
$("a[href^=www]").css("color","red");
$("a[href$=www]).css("color","red");
$("a[href='wwww']).css("color",""red);
$("a[href*=dafads"]).css("color","red");
四 jq常用的定位函数
$("div”).eq(2).css("color","red") $("div.eq(2)").css("color","red") 获取第二个div
$("div.gt(2)").css("color","red") 第二个div后面的div
$("div").eq(2).siblings().css("color","red") 获取第三个div的所有兄弟元素

$("div").not(":eq(2)").css("color","red")
  $("div").fliter(":eq(2)").css("color","red")
$(".class1").parent().css("color","red") 其父级
  $(".class1").parent().parent().css("color","red")  其父级的父级
  $(".class1").parents().css("color","red")  表示其所有的父级
  $(".class1").children().css("color","red")  找到其子元素
  $(".class1").prev().css("color","red")  找到上一元素
  $(".class1").prevAll().css("color","red")  
  $(".class1").next().css("color","red")
  $(".class1").nextAll().css("color","red") 
$("div").size() 获取一共有多少个div
$(".class1").css({"color":"red","color":"red"}) 这里是加多个样式,且加的是内联样式,权重是最高的

在js中直接增加删除css的class,但是css的文件必须含有才可以
$(".class1").addClass("c1 c2")这是又增加了两个类
$(".class2").removeClass("c1") 移除c1的这个类
  $(".class2").find(“span”).css("color","red") 移除c1的这个类


五 js常用的操作函数
setInterval(function(),time) 相隔多长时间,执行一个动作 clearInterval(id) -- 取消指定的setInterval函数将要执行的代码
append(<p>a<p>) 就是在什么里面加上什么
fadeIn fadeOut 渐变的显示和隐藏
hover(function(){},functiong(){}) 鼠标移上去执行一个事件,鼠标移下去执行一个事件
index()获取索引值





posted @ 2016-10-18 18:48  逗神呀  阅读(105)  评论(0)    收藏  举报