由於疫情的关系
大家已在家学习一个月
原本想说最要克服的是自制力
但没想到事情多到
我也没时间发闲~~~
本周分领域学习:
Web-JavaScript
引入:行内引入,内部引入,外部引入,动态引入
JS引入
行内引入→body: onload="alert('String要引号')">
内部引入→window.alert('内部引入')
外部引入→
动态引入
动态引入1→document.write('</script>');
动态引入2
<script>
const elemHead = document.getElementsByTagName('head')[0];
const elemScript = document.createElement('script');
elemScript.src = './js/dynamic.js';
elemHead.appendChild(elemScript);
</script>
DOM(document Object Model)
选取
操作
改变文字:textContent→document.querySelector('#id').textContent='Fanny';
加入HTML:innerHTML→document.querySelector('#id').innerHTML='test';→资安疑虑,如果有放入表单输入资料,容易被攻击
更改影像:src→document.querySelector('#pic').src='./img/'
加入CSS:style→document.querySelector('#id').style.borderLeft='solid 2px red';
:document.querySelector('#pic').setAttribute('src','./img....');
:document.querySelector('#pic').setAttribute('style','border: solid..');
套用格式:className→document.querySelector('#').className+=' .敲一个空格';
较直观的套用格式:classList→document.querySelector('#').classList.add(' classname', 'gg'); 注意:名字就好
event
click
mouse
keyup
额外补充:→抓表单值抓value
change
事件流Propagation:boxin,boxout
js预设冒泡→从点选对象往上层
捕获→
document.querySelector('#boxin').addEventListener('click',function()
{console.log(this.id);
e.stopPropagation;
});
number
String
const str='list';
const str=''+'list'+<'/ul'>;
const str='<li>list</ul>';
const str=<ul><li>list</li></ul>
document.querySelector('#list').innerHTML=str;
const age=20;
const str=我今天${age}岁
;→IE11以下不支援
变数型态:boolean, undefined, null
boolean→const isMobile=window.innerWidth≤480;
console.log(isMobile);
undefined→宣告却未赋
null→指向空
array&object
let arr=new Array();
arr=[1,2,3,4,'book'];
const arr=new Array(5, 6, 7, 'hi');
let arr=[];
arr=[2, 4, 5, 'go'];
const arr=[1, 3, 5, 'now'];
物件阵列
const obj=new Object();
obj.name='Fanny';
const obj={};
obj.age=30;
const obj={
name:'Fanny',
age=30
};
取物件长度:
object.keys(obj).length
function-for/if-else
可以独立取出来
interval&timeout
定时器interval
let count=0;
setInterval(function(){...},1000);//毫秒
暂停器timeout
let count=0;
setTimeout(function(){...},2000);//2秒後暂停
<<: 前端工程学习日记27天 header menu 三栏式 flex
前言 可选在上一篇中,提到一个概念就是暧昧。它是一种可以让程序介於「有值」、「没有值」的中间状态,这...
知道什麽是自动测试之後,我们来看看怎麽进行和资料库互动的自动测试。 测试目标 假设我们现有的资料关联...
当我们拿到一个现有的 Web Component 时 , 如何在 React 专案中引用呢 ? 利用...
昨天我们提到了该如何撰写 JSX,今天就来学习怎麽建立元件,来把同类型的 React element...
今天我们实作Users的CRUD,但今天因为花很多时间在前端的Header的排版,所以没有什麽时间可...