[英]Buttons that change units of measurement dynamically on page - Javascript
我正在尝试实现一个javascript函数,该函数将修改输出到字段中的结果值。
输出到字段的结果的示例是千字节和英磅。
但是,我在表单中包含了一些按钮,我将要使用它们来修改结果以使其进入
千兆字节,兆字节和便士
请参见下面的屏幕截图:
伪代码:
>Button pressed calls function.
>Function identifies what button user pressed
>If the button is related to currency unit then modify global variable **currency**
>If the button is related to data units then modify global variable **data**
>Recalculate all fields using new variable values and output to form.
我正在考虑实现它的方式是在Javascript中有两个Global变量,这些变量将根据所按下的按钮进行更改。 然后将它们用于数据和金钱的计算中。 为什么是全球性的? -好吧,我有单独的javascript函数来检索值并计算它们。
我需要输入有关如何检测按下哪个按钮的信息?
另外,如果您知道JS的任何类似示例,那也将很棒。
任何意见欢迎!
为了知道按下了哪个按钮,请向所有按钮和onclick事件处理函数添加一个onclick事件处理程序,您可以检测每个按钮的值,从中可以确定所单击的按钮。 例如
<input type="button" value="gb" onclick="identifyButton(this)" />
function identifyButton(obj)
{
alert(obj.value);
}
希望这对您有所帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.