jq基礎

$(function() {
          $(".dd").attr("class","cc").append("<h1 style='text-align:center'>我曹類 </h1>");
})css

attr()直接控制標籤屬性數組

$(function() {
          $("<h4> $() 能夠寫成 $(document).ready()</h4>").appendTo("body");
})瀏覽器

/*至關於屢次js中window.onload*/app

$(function(){
        $("<div class='inser'>來,插一段故事,跟我並列</div>").appendTo("body");
        $("<p>個人故事,插在後面</p>").insertAfter(".inser");
        $("<p>個人故事,插在前面</p>").insertBefore(".inser");
        $("<p>個人故事</p>").appendTo(".inset");
})函數

 /*DOM操做*/this

$(function() {
               var rr = " 123456789 ";
               rr = $.trim(rr);
               console.log(rr + " " + rr.length);
})seo

/*$ 做爲功能函數的前綴*/
/*例如去空格trim方法*/事件

window.onload = function(){              get

var cla = document.getElementsByClassName("aa")[0];
/*js能夠直接控制拿到,className,和id*/
cla.id = "gg";
cla.className = "cc";
cla.onclick = function(){
alert("改變id");
cla.id="";
alert("改變className");
this.cc = function(){
cla.className = "";
}
this.cc();
}io

}


$(function() {
                var ff = $.boxModel ? "w3c標準" : "IE"
                alert("目前支持的是" + ff + "盒子模型")
})

/*盒子模型 用$.boxModel檢測*/

$(function() {
/*$.each*/
var gg = new Array();
gg[0] = "第一個";
gg[1] = "第二個";
gg[2] = "第三個";
gg[3] = "第四個";
$.each(gg, function(index, value) {
console.log("序號爲:" + index + " 值爲:" + value);
})


var dd = {
a: 1,
b: 2,
c: 3
};
$.each(dd, function(shu, value) {
var uu = new Array();
if(value>2){
i++;
var i=0;
uu[i] = value;

}
$.each(uu, function(index,value) {
alert("序號爲:"+index+"值爲:"+value);
});
})
// $.each($.browser,function(property,value){
// console.log("瀏覽器名:"+property+"值爲:"+"value");
// })
/*數據過濾*/
$(function() {
var hh = [1, 2, 3, 4, 5, 6, 7, 7, 8, 9, 9]
var zhenghe = $.grep(hh, function(index, value) {
return value>4;
})
console.log(hh.join("-"));/*join()函數是獲取數組的值*/
console.log(zhenghe.join("-"));
})
/*數組轉化*/
$(function(){
var shuzu = ["a","b","c","d"]
var de = $.map(shuzu,function(b,a){/*map做用在於,第一個值變爲值,第二個爲屬性或者序號*/
return(b+a);
})
document.body.innerHTML = de;
})

 

$(function(){
$(".tian4").on("click",function(){
$(this).css({
background:"#ddd",
fontSize:"24px"
})
})
.on("mouseout",yichu = function(){/*關鍵在on*/
$(this).css({
background:"#fff",
fontSize:"14px"
})
})
$(".tian4").unbind("mouseout",yichu);/*移除 unbind*/
})

/*jq事件監聽*/

相關文章
相關標籤/搜索