我基本上想在點擊後禁用Rollout和rollover功能。我嘗試了一個if參數,但是我無法讓它工作。對不起,我是一個真正的初學者。如何使圖像按鈕在點擊後保持點擊狀態
我已經實現在母體div中單擊鼠標來改變文本,但仍然無法禁用其他功能。
<!DOCTYPE html>
<html>
<head>
<link href="styles/main.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="script.js"></script>
</head>
<script>
var Enabled = true;
function down()
{
document.getElementById("button").src = "images/click.png"; }
var Enabled = true;
function rollover()
{
if(Enabled == true)
{
document.getElementById("button").src = "images/on.png";
}else
{
document.getElementById("button").src = "images/click.png";
}
}
var Enabled = true;
function rollout()
{
if(Enabled == true)
{
document.getElementById("button").src = "images/off.png";
}else
{
document.getElementById("button").src = "images/click.png";
}
}
function myFunction() {
document.getElementById("demo").innerHTML = "Paragraph changed.";
}
<script/>
<body>
<h1>My Web Page</h1>
<div class="test1">
<button type="button" onclick="myFunction()">Try it</button>
</div>
<div class="row">
<div class="col"><p id="demo">A Paragraph</p></div>
<div class="col"><img src="images/off.png" id="button"
onMouseOver="rollover()" onMouseOut="rollout()"
onMouseDown="down()"
onClick="myFunction()"
onClick="this.innerHTML=down()
onMouseUp="rollover()";/></div>
<div class="col">col3</div>
</div>
</body>
</html>
統計通過修復您的內聯處理程序 - 你甚至可以看到他們在顏色編碼上失敗的地方。你不能有兩個onclicks。添加一個分號來堆疊它們:'onClick =「myFunction(); this.innerHTML = down()」'並記住你的引號。此外mouseDown觸發onClick – mplungjan
想法是在click或mousedown上添加一個類,然後在觸發這些(onMouseOver =「rollover()」onMouseOut =「rollout()」)觸發時檢查元素是否具有該類,如果有該類 – joyBlanks