我正在处理的代码是,一旦我单击一个按钮,两个电机将连续旋转,直到我按下另一个按钮停止。我希望能够按住一个按钮来旋转电机,但是一旦放开那个按钮,电机就会停止。
我的 remoteControl.php 文件的一部分:
$action = $_GET['action'];
$pin = mysql_real_escape_string($_GET['pin']);
if ($action == "forward"){
$setting = "1";
mysql_query("UPDATE pinStatus SET pinStatus='$setting' WHERE pinNumber='17';");
mysql_query("UPDATE pinStatus SET pinStatus='$setting' WHERE pinNumber='22';");
mysql_close();
header('Location: remoteControl.php'); ..........
........
<form action="remoteControl.php" method="get">
<input id="forward" type="image" src="uparrow.jpg" IMG STYLE="position:absolute; TOP:150px; LEFT:170px; WIDTH:50px; HEIGHT:50px;">
<input type=hidden name="action" value="forward">
</form>
我正在尝试使用的 JavaScript:
<head>
<script type="text/javascript">
function OnButtonDown (button) {
"can't figure out what to put";
}
function OnButtonUp (button) {
"can't figure out what to put";
}
function Init () {
var button = document.getElementById ("forward");
if (button.addEventListener) { // all browsers except IE before version 9
button.addEventListener ("mousedown", function () {OnButtonDown (button)}, false);
button.addEventListener ("mouseup", function () {OnButtonUp (button)}, false);
}
else {
if (button.attachEvent) { // IE before version 9
button.attachEvent ("onmousedown", function () {OnButtonDown (button)});
button.attachEvent ("onmouseup", function () {OnButtonUp (button)});
}
}
}
</script>
</head>
<body onload="Init ()">