diff --git "a/20\345\220\264\346\263\263\346\263\260/\344\275\234\344\270\232/2022.11.22--\344\275\234\344\270\232.md" "b/20\345\220\264\346\263\263\346\263\260/\344\275\234\344\270\232/2022.11.22--\344\275\234\344\270\232.md" new file mode 100644 index 0000000000000000000000000000000000000000..86eb5061804d8918132dab11d83b0e688f08a3c6 --- /dev/null +++ "b/20\345\220\264\346\263\263\346\263\260/\344\275\234\344\270\232/2022.11.22--\344\275\234\344\270\232.md" @@ -0,0 +1,15 @@ + \ No newline at end of file diff --git "a/20\345\220\264\346\263\263\346\263\260/\344\275\234\344\270\232/2022.11.23--\344\275\234\344\270\232.md" "b/20\345\220\264\346\263\263\346\263\260/\344\275\234\344\270\232/2022.11.23--\344\275\234\344\270\232.md" new file mode 100644 index 0000000000000000000000000000000000000000..ce050759c4e8a1c8668b1c52f921e97cd6fceda3 --- /dev/null +++ "b/20\345\220\264\346\263\263\346\263\260/\344\275\234\344\270\232/2022.11.23--\344\275\234\344\270\232.md" @@ -0,0 +1,34 @@ + +字符串长度 + + \ No newline at end of file diff --git "a/20\345\220\264\346\263\263\346\263\260/\344\275\234\344\270\232/2022.11.24--\344\275\234\344\270\232.md" "b/20\345\220\264\346\263\263\346\263\260/\344\275\234\344\270\232/2022.11.24--\344\275\234\344\270\232.md" new file mode 100644 index 0000000000000000000000000000000000000000..299b4a8984b2fc136d31c3db3dfd4f177e461a0b --- /dev/null +++ "b/20\345\220\264\346\263\263\346\263\260/\344\275\234\344\270\232/2022.11.24--\344\275\234\344\270\232.md" @@ -0,0 +1,20 @@ + \ No newline at end of file diff --git "a/20\345\220\264\346\263\263\346\263\260/\344\275\234\344\270\232/2022.11.28--\344\275\234\344\270\232.md" "b/20\345\220\264\346\263\263\346\263\260/\344\275\234\344\270\232/2022.11.28--\344\275\234\344\270\232.md" new file mode 100644 index 0000000000000000000000000000000000000000..e09917555f384ecb4ae9df87b114790e2b78945a --- /dev/null +++ "b/20\345\220\264\346\263\263\346\263\260/\344\275\234\344\270\232/2022.11.28--\344\275\234\344\270\232.md" @@ -0,0 +1,21 @@ +获取下拉框的值 + +var select = document.getElementById('sel'); + // var option = document.getElementsByTagName('option'); + select.onchange = () =>{ + for (var a of select) { + if (a.selected) { + console.log(a.innerText); + } + } + } +反选not + +$('#selectAll').change(function () { + var bool = $(this).is(':checked'); + if (bool) { + var truee = $("[class='fruit']").not($(':checked')); + $("[class='fruit']").not(truee).prop('checked',''); + truee.prop('checked','checked'); + } + }) \ No newline at end of file diff --git "a/20\345\220\264\346\263\263\346\263\260/\344\275\234\344\270\232/2022.11.29--\344\275\234\344\270\232.md" "b/20\345\220\264\346\263\263\346\263\260/\344\275\234\344\270\232/2022.11.29--\344\275\234\344\270\232.md" new file mode 100644 index 0000000000000000000000000000000000000000..426ce5bc744d000402cbe5499571b83b50d6de77 --- /dev/null +++ "b/20\345\220\264\346\263\263\346\263\260/\344\275\234\344\270\232/2022.11.29--\344\275\234\344\270\232.md" @@ -0,0 +1,17 @@ +封装 + +function oajaxx(get,json) { + var oAjax = new XMLHttpRequest(); + oAjax.open(get,json,true); + oAjax.send(); + oAjax.onreadystatechange = function () { + if(oAjax.readyState == 4){ + if(oAjax.status == 200){ + console.log(oAjax.responseText); + var obj = JSON.parse(oAjax.responseText); + console.log(obj); + } + } + } + } + oajaxx("GET","daaa.json"); \ No newline at end of file diff --git "a/20\345\220\264\346\263\263\346\263\260/\347\254\224\350\256\260/2022.11.23--jQuery\344\272\213\344\273\266.md" "b/20\345\220\264\346\263\263\346\263\260/\347\254\224\350\256\260/2022.11.23--jQuery\344\272\213\344\273\266.md" new file mode 100644 index 0000000000000000000000000000000000000000..dd3900d3b6c67c79647054c7ce48036bbb782043 --- /dev/null +++ "b/20\345\220\264\346\263\263\346\263\260/\347\254\224\350\256\260/2022.11.23--jQuery\344\272\213\344\273\266.md" @@ -0,0 +1,34 @@ +jQuery事件 +在文档加载后激活函数(常用写法) + +$(function(){ + $('#txt').keyup( + function () { + $('#num').text($('#txt').val().length); + } + ) +}); +常用事件 +click():鼠标单击 + +contextmenu()右键单击菜单(右键菜单按钮时间,可以拒绝右键菜单。) + +dblclick()双击触发 + +mousedown()鼠标按下 + +mouseup()鼠标松开 + +mousemove()鼠标移动 + +mouseout()鼠标移出元素 + +mouseover()鼠标移入元素 + +keydown()按下键盘 + +keyup()按下键盘松开 + +focus()获得焦点 + +blur()失去焦点 \ No newline at end of file diff --git "a/20\345\220\264\346\263\263\346\263\260/\347\254\224\350\256\260/2022.11.24--jQuery\347\273\221\345\256\232.md" "b/20\345\220\264\346\263\263\346\263\260/\347\254\224\350\256\260/2022.11.24--jQuery\347\273\221\345\256\232.md" new file mode 100644 index 0000000000000000000000000000000000000000..5d0070042a1560f36ce6d2520749e880f6bc2d45 --- /dev/null +++ "b/20\345\220\264\346\263\263\346\263\260/\347\254\224\350\256\260/2022.11.24--jQuery\347\273\221\345\256\232.md" @@ -0,0 +1,45 @@ +jQuery +绑定 +多个事件绑定一个函数 +bind('事件类型',函数) +多个事件绑定多个函数(键值对) +bind({'事件类型': 函数,'事件类型':函数}) +on绑定(动态元素绑定) +//$(父代选择器) +var text = $(''); +$(function () { + $('td').mousedown(function () { + $(this).append(text); + }) + }) +$(function () { + $('td').on('blur','#text',function () { + text.parent().text(text.val()); + }); + }) +解绑 +$(function () { + $('td').mousedown(function () { + $(this).append(text); + }).off() + //不带参移除所有事件 + }) +//带参移除特定事件 +一次事件(类似立即执行函数) +$(function () { + $('td').one(function () { + //当前元素只触发一次该事件 + $(this).append(text); + }) + }) +hover(鼠标移入移出) +$(function () { + $('div').hover( + function () { + $(this).css('color','red') + }, + function () { + $(this).css('color','white') + } + ) + }) \ No newline at end of file diff --git "a/20\345\220\264\346\263\263\346\263\260/\347\254\224\350\256\260/2022.11.28--jQuery\350\277\207\346\273\244.md" "b/20\345\220\264\346\263\263\346\263\260/\347\254\224\350\256\260/2022.11.28--jQuery\350\277\207\346\273\244.md" new file mode 100644 index 0000000000000000000000000000000000000000..0baec08161c0c7c665ff2dc86eaaa5306a171007 --- /dev/null +++ "b/20\345\220\264\346\263\263\346\263\260/\347\254\224\350\256\260/2022.11.28--jQuery\350\277\207\346\273\244.md" @@ -0,0 +1,29 @@ +事件委托 +target :源对象 + +currenttarget :当前调用该事件的对象 + +jquery.on()绑定方法 + +on('事件',元素,函数) + +e.keycode:键码值 + +dom创建元素 + +插入元素 + +clone():如果是true会连同事件一起复制, + +过滤方法 +eq():坐标过滤 + +is():p判断当前选择的元素集合中,是否有符合条件的元素有返回true,否则返回false + +filter():同辈过滤 + +has():子代过滤 + +find():查找当前元素的子代 + +not():符合条件的排除过滤掉 \ No newline at end of file diff --git "a/20\345\220\264\346\263\263\346\263\260/\347\254\224\350\256\260/2022.11.29--Ajax.md" "b/20\345\220\264\346\263\263\346\263\260/\347\254\224\350\256\260/2022.11.29--Ajax.md" new file mode 100644 index 0000000000000000000000000000000000000000..b4641b56e2ebeb49cbde8a8dfe7f4a81f203dead --- /dev/null +++ "b/20\345\220\264\346\263\263\346\263\260/\347\254\224\350\256\260/2022.11.29--Ajax.md" @@ -0,0 +1,32 @@ +Ajax +核心原理是异步无刷新 + +实时获取数据 + +第一步:发送http请求,创建XMLHttpRequest对象 +var oAjax = new XMLHttpRequest(); +第二步:请求行设置 +oAjax.open("GET","",true); +第三步:发送一个请求 +oAjax.send(); +第四步:接收返回 +oAjax.onreadystatechange = function () { + if(oAjax.readyState == 4){ + if(oAjax.status == 200){ + console.log(oAjax.responseText); + var obj = JSON.parse(oAjax.responseText); + console.log(obj); + } + } +} +JSON +JSON.stringify(): +将对象转发成json数据类型 + +var jsonn = JSON.stringify(obj) +console.log(jsonn); +JSON.parse(): +将json转发成对象 + +var objj = JSON.parse(jsonn); +console.log(objj); \ No newline at end of file diff --git "a/20\345\220\264\346\263\263\346\263\260/\347\254\224\350\256\260/2022.11.30--Ajax\350\216\267\345\217\226\346\225\260\345\200\274.md" "b/20\345\220\264\346\263\263\346\263\260/\347\254\224\350\256\260/2022.11.30--Ajax\350\216\267\345\217\226\346\225\260\345\200\274.md" new file mode 100644 index 0000000000000000000000000000000000000000..f4d464f5724117ce25744904b148dddca28672e2 --- /dev/null +++ "b/20\345\220\264\346\263\263\346\263\260/\347\254\224\350\256\260/2022.11.30--Ajax\350\216\267\345\217\226\346\225\260\345\200\274.md" @@ -0,0 +1,87 @@ +一,原生AJAX +1,GET方法;传送数据量小,处理效率高,安全性低,会被缓存 +send()中不需要添加任何参数,因为在连接服务器的时候就已经发送 +get请求就不必要设置 xhr.setRequestHeader(header,value) +var newAj=new XMLHttpRequest(); + newAj.open("GET","json练习.json",true); + newAj.send(); + newAj.onreadystatechange=function(){ + if (newAj.readyState==4) { + if (newAj.status==200) { + var obj=JSON.parse(newAj.responseText); + console.log(obj); + } + } + } +2,post方法;传送数据量大,处理效率低,安全性高,不会被缓存 +send()中需要添加参数,建议设置请求头 +参数可以是null或者xhr.send()|send(带有参数的)post请求在传递值的情况下必须 设置 xhr.setRequestHeader(header,value) + var xhr = new XMLHttpRequest(); + xhr.open('post', 'data.json', true); + xhr.send({ a: 100, b: 200 }); + //设置行头 + xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); + xhr.onreadystatechange = function () { + if (xhr.readyState == 4 && xhr.status == 200) { + console.log(xhr.response['No1']); + // 手动转成对象 + // var obj = JSON.parse(xhr.response); + } + } +3.响应数据处理;将返回的json类型的数据转换成对象 +1,手动转换 +var obj = JSON.parse(xhr.response) +console.log(obj.name) +2,自动转换 +//创建对象后设置: +xhr.responseType = 'json'; +console.log(xhr.response.name) +二,jQuery Ajax +1,$.get();执行get请求方式的ajax + $('button').eq(0).click( + function () { + $.get('data.json',{a:100,b:200},function (data) { + console.log(data); + },'json'); + } + ) +2,$.post();执行post请求方式的ajax + $('button').eq(1).click( + function () { + $.post('data.json',{a:100,b:200},function (data) { + console.log(data); + },'json'); + } + ) +3,$.getJSON() +通过Ajax获取服务器中JSON格式的数据 +“全局方法”,直接定义在jQuery对象(即“$”)下的方法 + $('button').eq(2).click( + function () { + $.getJSON('data.json',function (data) { + console.log(data); + }) + } + ) +4,$.getScript();动态加载JavaScript的方法 +通过AJAX来获取并运行一个外部JavaScript文件 +异步跨域加载JavaScript文件,可避免提前加载JavaScript文件 +减少服务器和客户端的负 担,加快页面加载速度 + $('button').eq(3).click( + function () { + $.getScript('test.js'); + } + ) +5,$.ajax();核心方法,所有的其他方法都是在内部使用此方法 +以上方法用ajax()都能实现 + $('button').eq(4).click( + function () { + $.ajax({ + url:'data.json', + type:'get', + data:{a:100,b:200}, + success:(data) => console.log(data), + error:()=> console.log('请求失败') + }) + } + ) \ No newline at end of file diff --git "a/20\345\220\264\346\263\263\346\263\260/\347\254\224\350\256\260/2022.12.01--Promise.md" "b/20\345\220\264\346\263\263\346\263\260/\347\254\224\350\256\260/2022.12.01--Promise.md" new file mode 100644 index 0000000000000000000000000000000000000000..a0c47bf015e3313b11608c239be76b956af38485 --- /dev/null +++ "b/20\345\220\264\346\263\263\346\263\260/\347\254\224\350\256\260/2022.12.01--Promise.md" @@ -0,0 +1,39 @@ +Promise +PromiseState +在每个promise对象中,状态只会改变一次 + +pending:准备中 + +fulfilled (成功) :调用了resolve函数,将状态改为成功 + +rejected (失败) :调用了reject函数,将状态改为失败 + +PromiseResult +接收resolve或者reject中的参数 + +const p = new Promise((resolve, reject) => { + // resolve('这是成功'); + reject('这是失败'); +}).then(data =>{ + console.log('成功then调用'); + return 123 + //catch:捕获异常 +}).catch( + function (e) { + console.log(e); + } +) +//then(成功时调用的函数,失败时调用的函数),返回值也是一个promise对象,pending +console.log(p) +GET +$('div').eq(0).one('mousemove', function () { + $.get('data.json', function (data) { + const { username } = data; + $.get('data1.json', function (data1) { + const contact = data1[username] + $.get('data2.json', function (data2) { + console.log(username + ':' + data2[contact]); + }) + }) + }) +}) \ No newline at end of file