代码如下:
switch(tagName){
case "span":
node = element.parent().parent();
element = element;
break;
case "td":
node = element.parent();
element = element.find("span");
break;
default:
node = element;
break;
}
以上语句等同于
if(tagName == "span"){
node = element.parent().parent();
element = element;
}else if(tagName == "td"){
node = element.parent();
element = element.find("span");
}else{
node = element;
}
注意每个case后,一定要加:break;
default,就相当于else
switch case
DEFAULT
switch
case
示例
js