我有一个无序列表的链接,它们都对应于我的 JS 文件中的不同事件。现在我正在使用
$('#gst').click(function(){
preset(gst);
});
$('#gsd').click(function(){
preset(gsd);
});
$('#ts').click(function(){
preset(ts);
});
$('#none').click(function(){
preset(none);
});
这是我的预设功能:
function preset(setter){
if(setter === gst){
currentPreset = gTitle;
$('#count').html(currentPreset);
}else if(setter === gsd){
currentPreset = gDesc;
}else if(setter === ts){
currentPreset = tLimit;
}else{
currentPreset = none;
$('#count').html(currentPreset);
}
}
它看起来很可怕。我知道有一种“干”的方法可以做到这一点。但我还没有找到一个。有谁知道做到这一点的最佳方法?这一定非常棒!
谢谢