我一直在努力的代碼是,一旦我點擊一個按鈕,兩個電機會連續旋轉,直到我點擊不同的按鈕停止。我希望能夠按住按鈕來旋轉電機,但一旦鬆開那個按鈕,電機就會停止。使用javascript的mousedown事件
部分我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()">
什麼 「馬達」 你在說什麼? – Ian
那麼,你在尋找能夠使圖像旋轉的代碼? – iConnor
對不起,不清楚。我正在研究Raspberry Pi。我使用它作爲Web服務器,樹莓還具有GPIO(輸出引腳),我正在使用它來驅動或旋轉直流電機。一旦我點擊uparrow圖像,它會發送命令來旋轉直流電機。 – Bros