javascript笔记

2022/3/6 14:51:34

本文主要是介绍javascript笔记,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

类与继承

'use strict'
class student{
    constructor(name){
        this.name = name;
    }
    hello(){
        alert('hello');
    }
}
class stu2 extends student{
    constructor(name,grade){
        super(name);
        this.grade = grade;
    }
    xx(){
        alert('hello');
    }
}
var x1 = new student('xiaoli');
var x2 = new stu2('xiaoming',100);

Date() Map() Set()

var time = new Date; // 获取当前时间
time.getDay(); // 礼拜几 0~6
var tms  =  time.getTime(); // 时间戳,毫秒
var time2 = new Date(tms);
 
var map = new Map( [ ['1','one'], ['2','two'] ] );
var set = new Set( ['1', '2', '1', '3'] );
for(let a of map){
    console.log(a) // ['1', 'one']  ['2', 'two']
}

BOM DOM

//bom 浏览器对象模型
window.innerHeight  .alert(1)
location.href   .host
screen.width
document.title .cookie
document.title  =  'newTitle' // 可以直接修改

//dom 文件对象模型
// 删除father下的第一个节点
var father = getElementById('fatherid'); 
father.removeChild(father.children[0]) 
//插入节点
var id = document.getElementById('idname'); // 
var newp = document.createElement('p'); // 创建标签p
newp.id = 'idp';
newp.style.color = 'red'; // 设置样式
newp.innerText = 'ppp'; // 文本
id.appendChild(newp);
var cssstyle = document.createElement('style'); // 创建标签style
cssstyle.setAttribute('type','text/css'); // 属性
cssstyle.innerHTML = 'div{ background: red}';
id.appendChild(cssstyle);

//jQuery(需下载)    公式:$('selector').action()
//jQuery API
$('#id .class').html('<br>') / .css({'color','red'});  .hide() .width() 等

//鼠标事件
<body>
    mouse: <span id = "mousespan"></span>
    <div id = "mousediv" style = "border:1px solid red;height: 1000px;">在这里移动</div>
</body>
<script>
        $(function(){
            $('#mousediv').mousemove(function (e) {
                $('#mousespan').text('x: '+e.pageX+'y: '+e.pageY);
            })
        });
</script> 


这篇关于javascript笔记的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程