<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<style type="text/css">
.xx{
border: solid red 3px;
}
.aa{
background-color: cyan;
}
.bb{
background-color: crimson;
}
</style>
<script src="js/jquery-3.3.1.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript">
$(function(){
//一,$工具方法
//1.1$each()遍历数组,对象的数据
//定义对象{}
//var stu={"name":"火狐","age":33};
//遍历对象
//console.info(stu.name,stu.age);
//$.each(stu,function(k,v){//k下标,v内容
// console.info(v);
//})
//定义数组[]
/* var names=["阿百川","aa","bb","cc"];
$.each(names,function(i,s){
console.info(s);
}) */
//定义对象数组
/* var stus=[{"name":"火狐","age":33},{"name":"广告","age":13}]
$.each(stus,function(i,s){
//第一种
//console.info(s.name,s.age);
//第二种
$.each(s,function(i,sa){
console.info(sa);
})
}) */
//1.2 $.trim()去除两边空格
// var str=" zking ";
// console.info($.trim(str).length);
//1.3 $.type得到数据类型
/* var str="sa";
console.info($.type(str)); */
//1.4 $.isArray() 判断是否是数组
/* var str=[1,1,1,1];
console.info($.isArray(str));
var str=[{"name":"火狐","age":33},{"name":"广告","age":13}];
console.info($.isArray(str));*/
//1.5 $.isFunstion() 判断是否是函数
//注意不能带括号 否则是调用方法
//console.info($.isFunction(myf));
//1.6 $.parseJSON() 解析json字符串转换为js对象/数组
//定义对象字符串
//var aa='{"name":"火狐","age":33}';
//console.info($.type(aa));
//将对象字符串转为字符串
//var stu=$.parseJSON(aa);
//console.info($.type(stu));
//console.info(stu.name,stu.age);
/* $.each(stu,function(i,s){
console.info(s);
}) */
//定义一个对象数组的字符串
//var str='[{"name":"火狐","age":33},{"name":"广告","age":13}]';
//将它转为js对象数组
//console.info($.type(str)));
/* var stra=$.parseJSON(str);
console.info($.type(stra));
$.each(stra,function(i,s){
console.info(s.name,s.age);
}) */
//二,属性和css
//2.1 attr()拿值也能设值
/* var mpath=$("#aa").attr("src");
console.info(mpath); 拿值 */
//设置值
/* $("#aa").attr("src","img/3.jpg");
$("#aa").attr("width","200px"); */
//2.2 removeAttr() 移除属性值
//$("#aa").removeAttr("src");
//$("#aa").removeAttr("width");
//2.3 addClass() 增加样式
//$("#aa").addClass("xx");//样式的叠加
//$("#aa").attr("class","xx");//样式的替换
//2.4 removeClass() 删除对应样式
//$("#aa").removeClass("xx");
//2.5 prop()和attr()的区别 仅限于属性值是boolean的时候
//$("#aa").attr("name","aa");
//$("#aa").prop("name","aa");
/* $("#ok").click(function(){
$(".abc").prop("checked",true);
})
$("#nook").click(function(){
$(".abc").prop("checked",false);
}) */
//案例3:优化表格的隔行换色
/* $("table tr:even").addClass("aa");
$("table tr:odd").addClass("bb"); */
//2.6 html()和text()的区别
/* var a=$("p").html();//会包含子标签
var b=$("p").text();//只会打印纯文本
console.info(a);
console.info(b); */
//2.7 val()拿值
//拿到文本框的value指
/* var a=$("#cc").val();
console.info(a); */
//赋值
//var a=$("#cc").val("aa");
//css
//1.设置值
//$("p").css("background","red");//单属性
//$("p").css({"background":"yellow","color":"red"});//多属性
//2.拿值 rgba() 红绿蓝 a为透明度取值范围0.1-1
var a=$("p").css("background","rgba(111,111,111)");
console.info(a);
})
function myf(){
}
</script>
</head>
<body>
<input type="text" value="选项" id="cc" />
<img src="img/reg.gif" id="aa" width="200px" class="yy" />
<hr />
<input type="button" value="全选" id="ok" />
<input type="button" value="取消全选" id="nook" />
<input type="checkbox" class="abc" value="a"/>a
<input type="checkbox" class="abc" value="b"/>b
<input type="checkbox" class="abc" value="c"/>c
<br />
<p>娃娃机<span>hhh</span></p>
<table border="1px" width="200px" height="200px">
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
</table>
</body>
</html>