我有一个选项卡bootstarp和一个页面标题,我想通过单击选项卡来更改页面标题,但我的jquery代码无法正常工作。
library(lpSolveAPI)
# Create data.table
dt <- data.frame(Date = c("March", "March", "March", "April", "April", "May", "June"),
Company = c("A", "A", "B", "B", "A", "C", "B"),
Return = c(0.03, 0.02, 0.01, 0.02, 0.01, 0.02, 0.03))
# Objective
obj <- -dt$Return
# Constraints
constraints <- list()
# Each month must appear once in the solution
for (month in unique(dt$Date)){
constraints[[paste0('month', month)]] <- list(xt = as.numeric(dt$Date == month),
type = "=",
rhs = 1)
}
# Each company can appear maximum 3 times in the solution
for (com in unique(dt$Company)){
constraints[[paste0('company', com)]] <- list(xt = as.numeric(dt$Company == com),
type = "<=",
rhs = 3)
}
# Build model
lprec <- make.lp(0, ncol = nrow(dt))
set.type(lprec, columns = seq(1,nrow(dt)), type = "binary")
set.objfn(lprec, obj = obj)
for (constraint in constraints){
add.constraint(lprec, xt = constraint$xt, type = constraint$type, rhs = constraint$rhs)
}
# Compute Solution
solve(lprec)
# Visualize solution
solution <- dt[get.variables(lprec)==1,]
solution
# Date Company Return
# 1 March A 0.03
# 4 April B 0.02
# 6 May C 0.02
# 7 June B 0.03
$(document.body).on('click', '.chooseChangePass li a', function(e) {
if ($("#chPass").hasClass("active")) {
$("#TitlePage").html("change Password");
} else {
$("#TitlePage").html("change UserName");
}
if ($("#chUserName").hasClass("active")) {
$("#TitlePage").html("change UserName");
} else {
$("#TitlePage").html("change Password ");
}
});
答案 0 :(得分:1)
您缺少代码,无法切换active
类。添加bootstrap.min.js文件。另外,代码中的else
语句是多余的。
在选项卡更改后更改页面标题的正确方法是使用Bootstrap navs events。您需要收听shown.bs.tab
事件。
$('a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
$('#page-title').html(e.target.text);
});
以下是Bootstrap 4.1.3的工作示例:https://codepen.io/anon/pen/OrJOQE?editors=1010
请确保查找正在使用的Boostrap版本的文档,因为版本3和版本4之间有重大变化。如果计划在同一页面上使用更多选项卡组,请将选项卡选择器更改为命名的选择器。