好吧,我的这个工作正常,但我的大脑已经死了,我确信有更好的方法来写这个:
// show results
let rtwEventList = $('#rtw-event-list'),
rtwCharityList = $('#rtw-charity-list');
$("#rtw-results").text({{ event_total }} + ' Results');
function showTotal(){
$(rtwEventList).click(function() {
$("#rtw-results").text({{ event_total }} + ' Results');
});
$(rtwCharityList).click(function() {
$("#rtw-results").text({{ charity_total }} + ' Results');
})
}
showTotal()
也许使用三元条件/表达式选项可能会更好?
最佳答案
你的意思是这样的吗?
$(rtwEventList).click(function() {
showTotal();
});
$(rtwCharityList).click(function() {
showTotal();
})
function showTotal(){
if(condition){
$("#rtw-results").text({{ charity_total }} + ' Results');
} else {
$("#rtw-results").text({{ event_total }} + ' Results');
}
}
关于javascript - 在两个js python之间切换对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60125703/