更新:
使用自己的代碼,它是這樣的:
if (this.getField("Button1").fillColor == ["RGB",1,1,1])
{
app.alert({ cMsg: "Switch to Grey", });
this.getField("Button1").fillColor = ["RGB",.5,.5,.5];
}
else if (this.getField("Button1").fillColor == ["RGB",.5,.5,.5])
{
app.alert({ cMsg: "Switch to Red", });
this.getField("Button1").fillColor = ["RGB",1,0,0];
}
else if (this.getField("Button1").fillColor == ["RGB",1,0,0])
{
app.alert({ cMsg: "Switch to Black", });
this.getField("Button1").fillColor = ["RGB",0,0,0];
}
else if (this.getField("Button1").fillColor == ["RGB",0,0,0])
{
app.alert({ cMsg: "Switch to White", });
this.getField("Button1").fillColor = ["RGB",1,1,1];
}
我以前的答覆如下:(用作參考)
這一個下面的內容純粹是針對JavaScript和HTML,而不是PDF,但您將會了解它是如何完成的。
你可以使用getElementById
和rgb
在JavaScript喜歡:
document.getElementById("button1").style.backgroundColor == "rgb(0, 255, 0)"
我將在這裏舉一個例子。比方說,你有一個像
<div>
<button id="button1" onclick="getcolor()" style="background-color:#0000FF; padding:5px;">Colored Button - Blue</button>
</div>
着色爲藍色的按鈕,我們希望將它更改爲綠色,如果它是一個綠色的顏色,我們希望將其更改爲藍色,這樣的話,你將有一個JavaScript這樣:
function getcolor()
{
var button_color = document.getElementById("button1").style.backgroundColor;
if (button_color == "rgb(255, 255, 255)")
{
alert("Switch color to Grey");
document.getElementById("button1").style.backgroundColor = "rgb(128, 128, 128)";
}
else if (button_color == "rgb(128, 128, 128)")
{
alert("Switch color to Red");
document.getElementById("button1").style.backgroundColor = "rgb(255, 0, 0)";
}
else if (button_color == "rgb(255, 0, 0)")
{
alert("Switch color to Black");
document.getElementById("button1").style.backgroundColor = "rgb(0, 0, 0)";
}
else if (button_color == "rgb(0, 0, 0)")
{
alert("Switch color to White");
document.getElementById("button1").style.backgroundColor = "rgb(255, 255, 255)";
}
}
順便說比較例如爲藍色時,比較它不應該是RGB(0,0,255)時要小心,在RGB空間,類似的顏色的每一個十進制值後,已經沒有空間:
if (button_color == "rgb(0,0,255)")
但它應該是這樣的:
if (button_color == "rgb(0, 0, 255)")
見我Updated Demo
如果你或許應該使用'...否則,如果... else',而不是在這裏。否則,我會看到每個這樣的'if'子句都會執行(因爲它們會檢查更改後的值)。 – raina77ow
當你比較你不使用的兩個值=單獨。您使用==或===因爲=意味着您將值分配給變量例如。 – Edper
@ user2446117發生了什麼事?你能最終解決你的問題嗎? – Edper