嗨,我对javascript很新.我希望能够在用户点击画布上的点(短按)时触发事件,如果保持点击向下1500毫秒,我应该有另一个功能.在mouseup完成之前我应该认识到长按.
例如:
el.addEventListener("mousedown", doMouseDown, false); el.addEventListener("mouseup", update, false);
function doMouseDown()
{
if (short press)
functionality of shortpress
if (longpress)
functionality of long press
}
function update()
//do some update of coordinates
Run Code Online (Sandbox Code Playgroud) 我是Java新手.我现在面临一个问题,我无法找到解决问题的最简单,最干净的方法.
假设我有3个参数(字符串)传递给一个函数(也可能是一个Hashmap).我想检查单个变量或变量组合是否不是Null并相应地采取行动.
例如,一种方法是使用if-else这种方式
if(a!=null && b == null && c == null) {
//doSomething
}
else if(a==null && b!= null && c == null ) {
//doSomething
}
else if(a==null && b0= null && c != null) {
//doSomething
}
......
//Similarly combination of two variables
if(a!=null && b != null && c == null) {
//doSomething
}
else if(a!=null && b== null && c != null) {
//doSomething
}
else if(a==null && b!= null && c != null) { …Run Code Online (Sandbox Code Playgroud)