简体   繁体   中英

How to put a button RESET and STOP on my accelerometer reading on HTML5

I'm having a problem on how to put a reset button and a stop button on my accelerometer on HTML5. Here is my code.

<script>
function init() { 

  var accelerometer = document.getElementById('accelerometer');
  if(window.DeviceMotionEvent) {
  window.addEventListener('devicemotion', function(event) {
            var x = parseInt(event.accelerationIncludingGravity.x);

            var y = parseInt(event.accelerationIncludingGravity.y);

            var z = parseInt(event.accelerationIncludingGravity.z);

            var acce = 'Acceleration:<br />';
            acce += 'x: ' + x +'<br />y: ' + y + '<br />z: ' + z + '<br />';

            accelerometer.innerHTML = acce;
          });
  }
}
</script>
       <script>
       function init() { 

       var accelerometer = document.getElementById('accelerometer');
       if(window.DeviceMotionEvent) {
        window.addEventListener('devicemotion', function(event) {
        var x = parseInt(event.accelerationIncludingGravity.x);

        var y = parseInt(event.accelerationIncludingGravity.y);

        var z = parseInt(event.accelerationIncludingGravity.z);

        var acce = 'Acceleration:<br />';
        acce += 'x: ' + x +'<br />y: ' + y + '<br />z: ' + z + '<br />'+'<input type=\"reset\" value=\"reset\" onclick=\"action here\"/>'+'<br/>'+'<button>Stop</button>';

        accelerometer.innerHTML = acce;
        });
        }
        }
        </script>

This Is Example Of Your Requirement Try Once .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM