原生判断是否存在某个类,手机端事件,手机端测试

原生方法,判断一个元素是否含有某个类,例子:

var firstP = document.getElementById("firstP");
        firstP.onclick=function(event){
            if (this.classList.contains('bg')==true) {
                this.setAttribute("class","single");
            }
            else{
                this.setAttribute("class","single bg");
            }
        }

 选择器一个写法

.single.bg{

  background-color:pink;

}//single和bg事实是作用于同一个元素上;

.single div{   } //single的所有后代div

.single >  .bg{  }//dingle的直接后代,儿子辈,这样写能提高检索性能,以后注意;

手机端事件总结

如何用手机测试自己写的web页面:

https://www.zhihu.com/question/37361845

posted @ 2018-03-24 23:56  仔行天下  阅读(192)  评论(0编辑  收藏  举报