2013-06-02 70 views
0

我似乎無法得到任何進一步與此。我更像是一個圖形人員,而不是程序員。
每次按下按鈕,我都需要一個按鈕來從白色循環到灰色循環再次變爲黑色循環。在一個pdf文件中將有超過一百個這些按鈕。
這是我到目前爲止已經試過:在PDF中使用JavaScript的多顏色更改按鈕

if (this.getField("Button1").fillColor = ["RGB",1,1,1]) 
    { 
    app.alert({ cMsg: "Switch to Grey", }); 
    this.getField("Button1").fillColor = ["RGB",.5,.5,.5]; 
    }; 

if (this.getField("Button1").fillColor = ["RGB",.5,.5,.5]) 
    { 
    app.alert({ cMsg: "Switch to Red", }); 
    this.getField("Button1").fillColor = ["RGB",1,0,0]; 
    }; 

if (this.getField("Button1").fillColor = ["RGB",1,0,0]) 
    { 
    app.alert({ cMsg: "Switch to Black", }); 
    this.getField("Button1").fillColor = ["RGB",0,0,0]; 
    }; 

if (this.getField("Button1").fillColor = ["RGB",0,0,0]) 
    { 
    app.alert({ cMsg: "Switch to White", }); 
    this.getField("Button1").fillColor = ["RGB",1,1,1]; 
    }; 

這可能嗎? 感謝

+0

如果你或許應該使用'...否則,如果... else',而不是在這裏。否則,我會看到每個這樣的'if'子句都會執行(因爲它們會檢查更改後的值)。 – raina77ow

+1

當你比較你不使用的兩個值=單獨。您使用==或===因爲=意味着您將值分配給變量例如。 – Edper

+0

@ user2446117發生了什麼事?你能最終解決你的問題嗎? – Edper

回答

0

更新:

使用自己的代碼,它是這樣的:

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,但您將會了解它是如何完成的。

你可以使用getElementByIdrgb在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

+0

這似乎沒有在PDF文件中工作...還有什麼我需要添加? – user2446117

+0

@ user2446117我的更新答案,如果它的工作。 – Edper

+0

仍然不能在PDF文件中工作.. – user2446117