長按儲存的方法
阿新 • • 發佈:2018-11-29
<!DOCTYPE html> <html lang="en"><head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no"> <title>長按</title> <style> body { -webkit-touch-callout: none !important; -webkit-overflow-scrolling: touch; } img,a{ pointer-events: none; } .long{ -webkit-user-select: none; } </style> <script src="jquery-3.0.0.min.js"></script> //當然也可以引入絕對路徑 <body> <div style="margin-left: 200px;margin-top: 100px"><button class="long" style="width:100px;height:100px; user-select: none;"></button></div> <div style="margin-top: 100px;margin-left: 100px"><span id="num" style="font-size: 100px;">5</span></div> <script> <!--阻止預設行為,相當於滑鼠右鍵--> window.document.oncontextmenu = function (e) { e.preventDefault(); }; var $long = $('.long'); var timer = null; $long.on('touchstart', function(){ plus('#num'); }); $long.on('touchend', function(){ clearTimeout(timer); }); function plus(ele){ var num = parseInt($(ele).text()); $(ele).text(++num); timer = setTimeout(function(){ plus(ele); }, 200); } </script>