我想删除宽度小于400px的浏览器的按钮(温度切换)。相反,我想触摸div来切换温度。我写了这段代码,但它不起作用。 “touchTemp”是包含div的id。
List<Unprocessed_DistanceTime_D> newListCDM = new ArrayList<>();
if (! listCDM.isEmpty()) {
Unprocessed_DistanceTime_D firstInGroup = listCDM.get(0);
Unprocessed_DistanceTime_D lastInGroup = firstInGroup;
for (int i = 1; i < listCDM.size() - 1; i++) {
Unprocessed_DistanceTime_D current = listCDM.get(i);
if (inSameGroup(firstInGroup, current)) { // current belongs to the same group
lastInGroup = current;
} else { // new group
// add old group to new list
newListCDM.add(firstInGroup);
if (lastInGroup != firstInGroup) {
newListCDM.add(lastInGroup);
}
}
}
// add last group to new list
newListCDM.add(firstInGroup);
if (lastInGroup != firstInGroup) {
newListCDM.add(lastInGroup);
}
}
概述蓝色div是触摸切换温度的区域。
答案 0 :(得分:0)
我建议你只需添加触摸处理程序以及点击即可完成并轻松测试。
var theElement = document.getElementById("touchTemp");
theElement.addEventListener("click", myFunction, false);
theElement.addEventListener("touchend", myFunction, false);
function myFunction(e) {
console.log("Screen width is less than 400px");
var text = $('#temperature').text();
if (text.slice(-1) === "F") {
$("#temperature").html(tempCelsius + " C" + "°");
} else {
$("#temperature").html(tempFahrenheit + " F");
}
e.preventDefault();
return false;
}