如何在不应用内部元素的情况下向DIV添加click属性?

时间:2016-08-23 21:26:29

标签: javascript jquery html animation

我有一个DIV,当点击时会展开以显示一些输入和按钮,并在再次点击时关闭,隐藏这些元素。我遇到的问题是当我点击按钮或输入框时,无论如何都会关闭动画。我知道我可以通过从DIV中取出输入和按钮来解决这个问题,但DIV对于它们的格式和组织非常重要。任何帮助都会很棒,谢谢!

HTML:

set.seed(1234567)  

data(iris)
iris$random <- rnorm(nrow(iris), 0, 1)

log.vars <- function(dset, vars, byvar, verbose = F){

  # a loop by levels of "byvar"

  for(i in 1:length(unique(dset[[byvar]]))){

    if(verbose == T){
      print(paste0("------ level=", unique(dset[[byvar]])[i], "----"))
    }

    # a loop by variables in "vars"

    for(j in 1:length(vars)){

      min.var <- min(dset[[vars[j]]][dset[[byvar]] == unique(dset[[byvar]])[i]])

      # if minimum of a given variable for a given level is greater than 0 then
      # calculate its logarithm;
      # otherwise, add to its value 1 and the mode of its minimum and calculate
      # its logarithm

      dset[[paste0("ln_", vars[j])]][dset[[byvar]] == unique(dset[[byvar]])[i]] <- 
        if(min.var > 0){
          log(dset[[vars[j]]][dset[[byvar]] == unique(dset[[byvar]])[i]])
        } else{
          log(dset[[vars[j]]][dset[[byvar]] == unique(dset[[byvar]])[i]] + 1 +
              abs(min.var))
        }
    }
  }
  return(dset)
}

iris2 <- log.vars(dset = iris,
         vars = c("Sepal.Length", "random", "Sepal.Width"),
         byvar = "Species",
         verbose = T)

head(iris2)

JS:

<div id='inputArea1' class='inputAreas'>
   <input id='email' class='evInput' placeholder='example@gmail.com'>
   <input id='comf' class='evInput' placeholder='Comfirmation Code'>
   <button id='sndCde' class='evBut'>Send Code</button>
   <button id='comfBut' class='evBut'>Comfirm</button>
</div>

完整代码:https://jsfiddle.net/dL2vzga0/

1 个答案:

答案 0 :(得分:3)

event.stopPropagation();可以完成这项工作:

$('#inputArea1').click(function(event){
  event.stopPropagation();
});

Fixed Fiddle