发表于: 2017-04-05 23:53:03
1 1102
今天完成的事:
学习JQ;
addClass描述: 为每个匹配的元素添加指定的样式类名.addClass( className ),className为一个String字符串,为指定元素添加这个classname的类.addClass( function(index, currentClass) ),这个函数返回一个或更多用空格隔开的要增加的样式名。接收index 参数表示元素在匹配集合中的索引位置和html 参数表示元素上原来的 HTML 内容。在函数中this指向匹配元素集合中的当前元素。
removeClass描述: 移除集合中每个匹配元素上一个,多个或全部样式。.removeClass( [className ] ),每个匹配元素移除的一个或多个用空格隔开的样式名。.removeClass( function(index, class) ),这个函数,返回一个或多个将要被移除的样式名。index 参数表示在所有匹配元素的集合中当前元素的索引位置。class 参数表示原有的样式名。
利用addClass和removeClass编写一个点击事件改变”this div“的背景颜色,当点击别的div 时之前的cilickClass背景还原,当前的DIV 背景颜色改变
代码:
<style type=
"text/css"
>
.clckClass{color:red;}
</style>
<script type=
"text/javascript"
>
var
removeClassA = $(
'ul li a.clckClass'
);
$(
'ul li a'
).bind(
'click'
,
function
(){
removeClassA .removeClass(
'clckClass'
);
$(
this
).addClass(
'clckClass'
);
removeClassA = $(
this
);
});
</script>
在做一个DOME 点击一次改变背景颜色,在点击颜色还原
*点击一次变色再次点击变回原色
$(function(){
var a=0;
$(".box ul").on("click",".name",function(){
//因为.name 是动态生成元素,所以先获取静态元素在点击动态元素name触发函数。
console.log(this);
a++;
if(a%2!=0){
$(this).css("background","#fff");
}
else{
$(this).css("background","red");
}
})
})
*/
学习javascript原型
JavaScript 不包含传统的类继承模型,而是使用 prototype 原型模型。
function Foo() {
this.value = 42;
}
Foo.prototype = {
method: function() {}
};
function Bar() {}
// 设置Bar的prototype属性为Foo的实例对象
Bar.prototype = new Foo();
Bar.prototype.foo = 'Hello World';
// 修正Bar.prototype.constructor为Bar本身
Bar.prototype.constructor = Bar;
var test = new Bar() // 创建Bar的一个新实例
// 原型链
test [Bar的实例]
Bar.prototype [Foo的实例]
{ foo: 'Hello World' }
Foo.prototype
{method: ...};
Object.prototype
{toString: ... /* etc. */};
test 对象从 Bar.prototype 和 Foo.prototype 继承下来;因此, 它能访问 Foo 的原型方法 method。同时,它也能够访问那个定义在原型上的 Foo 实例属性 value。 需要注意的是 new Bar() 不会创造出一个新的 Foo 实例,而是 重复使用它原型上的那个实例;因此,所有的 Bar 实例都会共享相同的 value 属性。
明天计划的事:
继续学习JS jq
继续任务4的编写
遇到的问题:
基础不够扎实,写起来很困难
收获:
对JS原型有了基础的认识。
评论