获取计算HTML代码 [英] Get Calculation HTML Code

查看:98
本文介绍了获取计算HTML代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何值=获取答案

如果value是值<50,则将5减去给定值.
如果值大于或等于50,则将给定值的10%减去给定值.

我想获取用于此计算的HTML/javascript代码.
Thanx ....

Value Any = Get Answer

if value is value<50 than deduct 5 into given value.
if value is value>50 than deduct 10% of given value into given value.

I want to get HTML/javascript Code for this calculation.
Thanx....

推荐答案

第一答案
您不能使用HTML进行计算,因为它是静态的,因此您应该使用javascript或类似的解决方案.

尝试一下,如果遇到问题,请回来.

第二答案
为了调用javascript代码段,您将必须创建一个表单并响应发送按钮:
FIRST ANSWER
You can''t do calculations using HTML as it is static, in order to do that you should use javascript or similar solutions.

Try it and come back if you face some problems.

SECOND ANSWER
In order to call a javascript code snippet you will have to create a form and react to the send button:
<form name=''Myform'' action=''file_to_call.html'' method=''POST'' enctype=''application/x-www-form-urlencoded'' onsubmit=''return javascript_function();''>


在这里,您可以了解进入"file_to_call"之前如何调用函数.

请参阅html中的表单和javascript,以获取有关如何在html中实现javascript调用的更多信息和示例.


Here you can see how to call a function before getting into the "file_to_call".

See forms and javascript in html to get more information and good samples on how to implement javascript calls in html.


众所周知,JavaScript是一种基于事件/动作的客户端脚本语言.因此,在执行该操作时,只需调用一个包含计算逻辑的javascript函数即可.
As we all know that Javascript is an event/action based client side scripting language. So on the action just call a javascript function which s''d contain the logic of your calculation.


基本上就是这样:

This is basically it:

function calculate(value)
{
    var retVal;
    if(value <= 50)
        retVal = value - 5;
    else
        retVal = value * 0.95;
    return retVal;
}



您其他javascript代码中的某处:



Somewhere in your other javascript code:

var someValue = 50;
// other statements
// more statements
someValue = calculate(someValue);



问候,

—曼弗雷德(Manfred)



Regards,

— Manfred


这篇关于获取计算HTML代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆