在Javascript中添加和删除带有操作的类

时间:2017-11-08 21:24:52

标签: javascript jquery

如何通过在第二次单击后单击并删除来添加类。

# packages and sample data/model
library(GGally)
library(broom)
library(ggplot2)

d <- as.data.frame(Titanic)
reg2 <- glm(Survived ~ Sex +  Class + Age, family = binomial, data = d, weights = d$Freq)

# eg with gg coeff
ggcoef(reg2, exponentiate = TRUE, exclude_intercept = TRUE, errorbar_height = .2, color = "blue")


# set defaults
vline <- TRUE
vline_intercept <- "auto"
vline_color <- "gray50"
vline_linetype <- "dotted"
vline_size <- 1
conf.level <- 0.95
conf.int <- TRUE
exponentiate <- FALSE
errorbar_color = "gray25"
errorbar_height = 0
errorbar_linetype = "solid"
errorbar_size = 0.5

# type ggcoef in to the console to get the function. It orders on name with
# no option to change it
x <- broom::tidy(reg2, conf.int = conf.int, conf.level = conf.level, 
                 exponentiate = exponentiate)

# these two lines will change the ordering based on estimate
x$variable <- factor(x$term, levels=unique(as.character(x$term)) )
x <- transform(x, variable = reorder(variable, -estimate) ) 

# rest produce the ggplot in the function. Play around with settings as required
# perhaps rewrite the function with your added arguments and store ;)
p <- ggplot(x, mapping = aes_string(y = "variable", x = "estimate"))

if (vline) {
  if (exponentiate) {
    if (vline_intercept == "auto") {
      vline_intercept <- 1
    }
    p <- p + geom_vline(xintercept = vline_intercept, 
                        color = vline_color, linetype = vline_linetype, 
                        size = vline_size) + scale_x_log10()
  }
  else {
    if (vline_intercept == "auto") {
      vline_intercept <- 0
    }
    p <- p + geom_vline(xintercept = vline_intercept, 
                        color = vline_color, linetype = vline_linetype, 
                        size = vline_size)
  }
}




if (conf.int & "conf.low" %in% names(x) & "conf.high" %in% 
    names(x)) 
  p <- p + geom_errorbarh(aes_string(xmin = "conf.low", 
                                     xmax = "conf.high"), color = errorbar_color, height = errorbar_height, 
                          linetype = errorbar_linetype, size = errorbar_size)

p <- p + geom_point(aes_string(y = "variable", x = "estimate"))
p

我想添加&#39; open&#39;像第二个例子一样按下课时的课程

<header id="header" class="header-vertical dark">

感谢您的支持:)

2 个答案:

答案 0 :(得分:0)

使用toggle方法!像这样:

&#13;
&#13;
var header = document.getElementById("header");

header.addEventListener("click", myFunc, false);

function myFunc() {
   header.classList.toggle("active");
 }
&#13;
.normal {
  background-color: red;
}

.active {
  background-color: green;
}
&#13;
<button onclick="myFunc()">click here</button>
<h1 id="header" class="normal">The Header</h1>
&#13;
&#13;
&#13;

在您的情况下,只需将.active替换为您的班级.open

答案 1 :(得分:-1)

Toggleclass,正是您所寻找的