Javascript 在jQuery中切换HTML按钮时,时间戳不随活动日期时间更新?

Javascript 在jQuery中切换HTML按钮时,时间戳不随活动日期时间更新?,javascript,jquery,html,Javascript,Jquery,Html,var timeIn=new Date(); $(“.BtnTime1”)。单击(函数(){ 如果($(this).text()=“绿色”){ $(this).text(timeIn); }否则{ $(此).text(“绿色”); }; }); var timeOut=新日期(); $(“.BtnTime2”)。单击(函数(){ 如果($(this).text()=“绿色”){ $(this).text(超时); }否则{ $(此).text(“绿色”); }; }); 房间里的时间 休息

var timeIn=new Date();
$(“.BtnTime1”)。单击(函数(){
如果($(this).text()=“绿色”){
$(this).text(timeIn);
}否则{
$(此).text(“绿色”);
}; 
});
var timeOut=新日期();
$(“.BtnTime2”)。单击(函数(){
如果($(this).text()=“绿色”){
$(this).text(超时);
}否则{
$(此).text(“绿色”);
}; 
});

房间里的时间
休息室
时差
绿色
绿色


您需要在单击函数中包含
timeIn
timeOut
值:

$(“.BtnTime1”)。单击(函数(){
如果($(this).text()=“绿色”){
var timeIn=新日期();
$(this).text(timeIn);
}否则{
$(此).text(“绿色”);
}; 
});
$(“.BtnTime2”)。单击(函数(){
如果($(this).text()=“绿色”){
var timeOut=新日期();
$(this).text(超时);
}否则{
$(此).text(“绿色”);
}; 
});

房间里的时间
休息室
时差
绿色
绿色


@Taplar有意义。接受并更新此建议非常感谢您的帮助和时间!这似乎奏效了!