加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 创业 > C语言 > 正文

DOM编程艺术

发布时间:2020-12-15 00:46:19 所属栏目:C语言 来源:网络整理
导读:样式操作 设置样式 element.style.cssText='border-color:red;color:red;' 获取样式 element.style.color //只能用于行内样式 window.getComputedStyle(element).color; //ie9下使用currentStyle function getStyle(element,cssPropertyName){ if (element.c

样式操作

设置样式

element.style.cssText='border-color:red;color:red;'

获取样式

  • element.style.color //只能用于行内样式

  • window.getComputedStyle(element).color; //ie9下使用currentStyle

function getStyle(element,cssPropertyName){
            if (element.currentStyle) {
                alert(element.currentStyle[cssPropertyName]);
            }else{
                alert(getComputedStyle(element,null)[cssPropertyName])
            }
        }

事件

事件注册

var elem=document.getElementById('div1');
var clickHandler=function(event){
    //to do
}
elem.addEventListener('click',clickHandler,false);

elem.onclick=clickHandler

取消事件注册

elem.removeEventListener('click',false);
elem.onclick=null;

阻止事件传播

  • event.stopPropagation

  • event.cancelBubble=true //ie

  • event.stopImmediatePropagation()

默认行为

  • event.preventDefault

  • event.returValue=false //ie

事件分类

数据通信

常见HTTP状态码

ajax

screenshot 2.png

get请求

var url = 'example.json?'+serialize(formdata);
xhr.open('get',url,true);
xhr.send(null);

post请求

xhr.open('post','example.json',true);
xhr.send(serialize(formdata));

数据存储

cookie

screenshot 1.pngscreenshot 4.pngscreenshot 3.pngscreenshot 2.png

storage

  • localStorage 时间永久

  • sessionStorage 浏览器回话事件

BOM

方法:

  • alert

  • confirm

  • prompt

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读