是否有可能使用鼠标按下和鼠标松开事件在同一个按钮? [英] Is it possible to use the mousedown and mouseup event on the same button?

查看:134
本文介绍了是否有可能使用鼠标按下和鼠标松开事件在同一个按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

本项目涉及控制通过LAN一辆玩具车。

This project involves controlling a toy car over LAN.

在我的HTML页面中,有5个按钮上,下,左,右,停。
我的code是这样的:在说向上的用户点击,值被发送到一个PHP页面进行处理,并将处理字符串获取打印另一个PHP页面上的一个Arduino读

On my html page, there are 5 "buttons";up, down, left, right, stop. My code works like this: Say the user clicks on "up", a value gets sent to a php page for processing and the processed string gets printed on another php page for an arduino to read.

对于汽车停下来,用户必须点击停止。

For the car to stop, the user has to click on stop.

<html>
<head>
</head>

<form name="motorform" action="motorboardprocess.php" method="post">
<tr><p align='center'><font face="BN machine" size="6" color="royalblue">Motor Shield</font></tr>
<tr>
    <input id="forward" type="image" src="up.png" name="forward">
</tr> 
<tr>
    <input id="left" type="image" src="left.png"  name="left">
    <input id="stop"type="image" src="stop.png"  name="stop">
    <input id="right" type="image" src="right.png" name="right">
</tr>
<tr>      
    <input id="backward" type="image" src="down.png" name="backward">
</tr>   
</form>
</body>
</html>

和该PHP ...

<?php

if (isset($_POST['forward_x'], $_POST['forward_y'])){
    $myFile = "mtboardcom.php";
    $fh = fopen($myFile, 'w') or die("can't open file");    
    $stringData = "<?php\n";
    fwrite($fh, $stringData);
    $stringData = "echo ".'"<forward>"'."\n";
            fwrite($fh, $stringData);
    $stringData = "?>\n";
            fwrite($fh, $stringData);
    fclose($fh);        
}

else if (isset($_POST['left_x'], $_POST['left_y'])){
    $myFile = "mtboardcom.php";
    $fh = fopen($myFile, 'w') or die("can't open file");    
    $stringData = "<?php\n";
    fwrite($fh, $stringData);
    $stringData = "echo ".'"<left>"'."\n";
            fwrite($fh, $stringData);
    $stringData = "?>\n";
            fwrite($fh, $stringData);
    fclose($fh);        
}
//and so on.....

Arduino的内容如下:

the arduino reads:

<?php
    echo "<forward>"
?>

所以,问题是,我怎么使用的鼠标按下鼠标松开从jQuery的事件
除去停止按钮。

So the question is, how do I make use of the mousedown and mouseup events from jquery to remove the stop 'button'.

或者另外一种情况:用户按住按钮,动车和释放按钮,把车停下来。

Or another scenario: the user holds down the button to move the car and releases the button to stop the car.

鼠标按下,字符串前进由Arduino的读取。

On mousedown, a string 'forward' is read by the arduino.

鼠标松开在同一按钮上,串停止由Arduino的读取。

mouseup on the same button, string 'stop' is read by the arduino.

推荐答案

当然,你可以订阅在Javascript中两个不同的事件。刚挂接到事件:

Of course you can subscribe to two different events in Javascript. just hook into the events:

var field = document.getElementsById('#idName');

field.onmousedown = function(){

}

field.onmouseup = function(){

}

或者jQuery的:

Or for jquery:

var field = $('#idName');

field.mousedown(function(){

}).mouseup(function(){

});

这篇关于是否有可能使用鼠标按下和鼠标松开事件在同一个按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆