如何制作可点击的横幅

时间:2018-11-06 15:48:41

标签: javascript jquery

我有一个#Determine the input and output parameters input_file <- choose.files() output_eu <- "eu.xlsx" output_noteu <- "noteu.xlsx" #list of EU countries eu <- c("Andorra","Austria","Belarus","Belgium","Bosnia and Herzegovina","Bulgaria","Croatia","Czech Republic","Denmark","Estonia","Finland","France","Germany","Greece","Hungary","Iceland","Ireland","Italy","Latvia","Liechtenstein","Lithuania","Luxembourg","Malta","Moldova","Monaco","Montenegro","Netherlands","Norway","Poland","Portugal","Romania","Russia","San Marino","Serbia","Slovakia","Slovenia","Spain","Sweden","Switzerland","Ukraine","United Kingdom") #reading the csv table d <- read.table(input_file, sep = ";", header = TRUE, check.names = FALSE) # get all cases where there is some text in the Update field updates <- d[d$Update != "", ] #within updates are there countries in EU i <- updates$Country %in% eu eu_up <- updates[i,] noteu_up <- updates[!i,] #importing openxlsx library library(openxlsx) #create the workbook for each one wb_eu <- createWorkbook() wb_xeu <-createWorkbook() #adding the data to each corresponding workbook addWorksheet(wb_eu, "European Sites") addWorksheet(wb_xeu, "Non-European Sites") #write our tables into each writeDataTable(wb_eu, 1, eu_up, startRow=1, startCol=1, tableStyle="TableStyleLight11") writeDataTable(wb_xeu, 1, noteu_up, startRow=1, startCol=1, tableStyle="TableStyleLight11") #setting our column widths setColWidths(wb_eu, 1, cols=1:26, widths = "auto") setColWidths(wb_xeu, 1, cols=1:26, widths = "auto") #saving our workbooks saveWorkbook(wb_eu, "European Sites updated.xlsx", overwrite = TRUE) saveWorkbook(wb_xeu, "Non-European Sites updated.xlsx", overwrite = TRUE) ,里面有一个链接。当我单击一个div时,它应该打开链接(例如:google.com),但是当我单击该按钮时,它应该打开另一个链接。

div
<div class="sc-banner">
    <a href="#" target="_blank">Button</a>
</div>

1 个答案:

答案 0 :(得分:2)

问题是因为a的click事件正在传播DOM并触发div上的点击处理程序。

您可以通过两种方法解决此问题。首先,检查div处理程序中的事件目标是什么:

$(".sc-banner").click(function(e) {
  e.stopPropagation();
  if (e.target.tagName !== 'A')
    window.open('http://google.com', "_blank");
});

或者,您可以在a上添加另一个事件处理程序,以调用stopPropagation()

$(".sc-banner").click(function(e) {
  e.stopPropagation();
  window.open('http://google.com', "_blank");
});

$(".sc-banner a").click(function(e) {
  e.stopPropagation();
});