在pdf中使用javascript更改多颜色按钮
Multi-Color changing button using javascript in a pdf
我似乎不能再进一步了。比起程序员,我更喜欢图形。
我需要一个按钮循环从白色到灰色到红色再到黑色到白色每次按下按钮。在一个pdf文件中将有超过一百个这样的按钮。
这是我到目前为止所尝试的:
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];
};
这可能吗?由于
更新:
使用您自己的代码,它看起来像这样: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,但你会看到它是如何完成的。
你可以在JavaScript中使用getElementById
和rgb
:
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中的空格,例如蓝色,在比较时不应该是rgb(0,0,255),它在颜色的每个十进制值之后没有空格,如:
if (button_color == "rgb(0,0,255)")
但是应该是这样的:
if (button_color == "rgb(0, 0, 255)")
参见my Updated Demo
相关文章:
- 单击时将文本的颜色更改为随机颜色(按钮)
- 使用event.target.classlist区分按钮颜色
- 将上次单击的按钮和访问过的按钮(未访问过的)的颜色分开
- 如何在单击按钮时更改整行的颜色
- 如何使用带有多个按钮的javascript更改按钮颜色
- 更改HTML按钮值的颜色,其中值来自调用Javascript的onclick
- 切换按钮的背景颜色
- 输入类型按钮在按下时更改颜色
- 如果我在jquery移动中使用“onclick”,按钮不会改变颜色
- Highcharts上下文按钮颜色
- 单击按钮更改颜色/清除画布时画布出现问题
- 在提交时更改按钮颜色,直到输入新文本
- 如何在mozilla firefox扩展中更改自定义工具栏按钮的颜色
- 当用户将鼠标指针放在窗体按钮上时,该按钮必须更改颜色
- 如何更改颜色按钮无需重新加载页面
- 调暗灯光/更改颜色按钮与Javascript/html
- jWYSIWYG设置字体颜色按钮
- 在pdf中使用javascript更改多颜色按钮
- ASP.NET如何更改表行上的背景颜色按钮单击+行条目
- 如何颜色按钮和保持状态