-1

我正在使用 POST 向 arduino 发送命令。我希望在按住按钮时重复向上命令。这是我正在尝试的...

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<title></title>

        <link rel="stylesheet" href="../templates/mainkibblynibblytemplate/css/kibbly-jquery.css" />
        <script src="http://code.jquery.com/jquery-1.9.1.js"></script>
        <script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
    <script type="text/javascript">
        var timeout, clicker = $('#upbutton');

        clicker.mousedown(function () {
                          timeout = setInterval(function () {
                                                $.post('http://192.168.1.77:8888/', {
                                                       text: 'up'
                                                       });
                                                }, 500);

                          return false;
                          });

        $(document).mouseup(function () {
                            clearInterval(timeout);
                            return false;
                            });
        </script>

</head>
<body>
<button id="upbutton">Test</button>
</body>
</html>
4

2 回答 2

0

您必须将事件 mouseup 处理为按钮并删除“return false”

像这样:

clicker.mousedown(function () {
   timeout = setInterval(function () {
                 $.post('http://192.168.1.77:8888/', {
                       text: 'up'
                 });
              }, 500);
});

clicker.mouseup(function () {
    clearInterval(timeout);
 });
于 2013-09-25T21:08:22.287 回答
0

您可以通过在 JavaScript 中使用onkeydown事件来实现这一点。在 onkeydown 事件中,您可以循环显示您想要执行的结果。

于 2013-09-25T20:39:01.750 回答