1、animate 动画
方法:$(selector).animate(styles,speed,easing,callback)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<div id="box" style="width: 100px;height: 100px;background-color: #ccc;"></div>
<script src="js/jquery-2.1.0.js"></script>
<script>
var currHeight = 0;
$('#box').click(function(){
currHeight += 100;
$(this).animate({height:currHeight,width:currHeight},function(){
console.log('1');
});
});
</script>
</body>
</html>
2、JQuery给元素绑定click事件多次执行的解决方法
$("#sdfsd").on("click",function(e){ ***** });
这种方法只会在原click方法中继续添加新方法;
解决办法更改绑定方法为:
$("#sdfsd").unbind("click").click(function(e){ ***** });
在绑定新click方法前对元素所绑定的click方法解绑
3.判断数据返回类型(js判断undefined类型)–typeof
var id = $(this).attr("id").substring(0,9);
这个看似没问题,但如果当前标签下不存在id属性, 那么 $(this).attr(“id”) 就会返回一个undefined,此时 .substring 就会抛异常,(.substring 为截取字符串,显然 undefined 不是一个有效的字符串)
这时就要使用 typeof 判断:
var idStr = $(this).attr("id");
//判断是否能获取到id(
//typeof 返回的是字符串,有六种可能:"number"、"string"、
"boolean"、"object"、
"function"、"undefined")
if(typeof(idStr) == "undefined"){
}else{
var id = idStr.substring(0,9);
$("#favoriteId").val(id);
}
4.禁用css样式
<script type="text/javascript">
$(function(){
// 禁用css样式
// resetCss为css的文件的id,<link ... id = "resetCss">
//document.getElementById("resetCss").disabled = true;
$("#resetCss").attr("disabled",true);
})
</script>
作者: 慕冬雪
链接:http://www.imooc.com/article/2505
来源:慕课网