在 HTML 页面中,我有 7 个按钮带有以下 ID:#I、#II、#III、#IV、#V、#VI、#VII放置在rContainer div 中。我想设置与触摸按钮相关的iActiveButton变量。我的代码似乎工作正常,但我觉得它可以增强和缩短。任何的想法?
var iActiveButton;
function touchHandler(){
console.log(iActiveButton);
}
rContainer.addEventListener("touchstart", function(){
I.addEventListener("touchstart", function(){iActiveButton = 1;}, false);
II.addEventListener("touchstart", function(){iActiveButton = 2;}, false);
III.addEventListener("touchstart", function(){iActiveButton = 3;}, false);
IV.addEventListener("touchstart", function(){iActiveButton = 4;}, false);
V.addEventListener("touchstart", function(){iActiveButton = 5;}, false);
VI.addEventListener("touchstart", function(){iActiveButton = 6;}, false);
VII.addEventListener("touchstart", function(){iActiveButton = 7;}, false);
touchHandler();
}, false);
繁花不似锦
沧海一幻觉
相关分类