日期:2014-05-16  浏览次数:20362 次

这两个语句啥意思
this.className+=(this.className.length>0? " ": "") + "mhover";  
this.className=this.className.replace(new RegExp("( ?|^)mhover\\b"),"")

------解决方案--------------------
this.className+=(this.className.length>0? " ": "") + "mhover"; 
这句等价于
this.className=this.className+(this.className.length>0? " ": "") + "mhover"; 
判断
this.className.length是不是大于0是的话空加上mhover。。不是就直接mhover
this.className=this.className.replace(new RegExp("( ?|^)mhover\\b"),"")
这句是通过正则替换this.className
------解决方案--------------------
第二格正则的意思大体是将' mhover\b' 'mhover\b'或者以'mhover\b'开头的部分去掉
------解决方案--------------------
(this.className.length>0? " ": "")+a,

例如 这样 class="1", 当你想在加多个class名字或者多几个是不是 class="1 2 3 4 。。。"注意里面的空格,

所以很明显 是判断 class="" 里面是否有名字,例如(class="1"),如果有的话就是(空格)+a,变成了
class="1 a",如果没有的话 就是直接 class="a";

两个双引号 第一个" " 是表示空格的意思例如:"a b"
第二个"" 是这样"ab"