可以用html/css进行简单的计算,但没有javascript或后端? [英] possible to do simple calculation with html/css, but without javascript, or backend?

查看:42
本文介绍了可以用html/css进行简单的计算,但没有javascript或后端?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

许多Webview插件(例如Android Webview)的默认行为是禁用javascript执行.在这些情况下,仍然可以不使用JS,仅使用纯HTML甚至使用CSS来进行简单的计算(例如,在文本框中将两个数字相加)吗?

The default behavior on many of the Webview plugins, for example the Android Webview, is to disable javascript execution. Is it possible at all to still perform simple calculations (to add up the two numbers in the text box for example) using no JS, just pure HTML, or even CSS on these situtations?

请注意,< input onclick ="c = a + b"/> 是javascript.

note that <input onclick="c=a+b"/> is javascript.

推荐答案

一个有趣的问题,(我希望)我可以尽可能完整地回答.

An interesting question which (I hope) I can answer as fully as possible.

从逻辑上讲,是的.无需使用JS即可进行简单的计算...但是对此有很多警告.

Logically, Yes. It is possible to do simplistic calculations without using JS... however there are are a great many caveats to this.

应对 no-js 问题的最好方法是采用服务器端语言(例如PHP)或类似的算法进行

The best way to counter the no-js problem is to employ a server-side language like PHP or such to do the arithmetic as @ACV rightly says.

但是,请参见纯CSS实验,该实验巧妙地使用了 calc() CSS函数.注意事项?它在浏览器中的支持非常有限,请参见 CanIUse 支持表.使支持问题更为复杂的是,它可能仅适用于基本算术-四舍五入到最接近的整数.如果您需要任何程度的准确性,那就不好了.

However, see this pure CSS experiment which cleverly uses the calc() CSS function. The caveat to this? It has very limited support in browsers see the CanIUse support table. Compounding the support issue is it may only be possible for basic arithmetic - rounding to the nearest whole number. Not great if you need any degree of accuracy.

值得在< output> 标记

It is worth looking at the W3CSchools material on the <output> tag here but again, the ol' browser support caveat rears it's ugly head once more - salivating at the prospect of devouring another web designer's soul... (IE does not support it)

总结并回答您的问题,是的!但不是.除了明显的浏览器限制外,最好在没有JS的情况下使用服务器端代码进行计算.

In conclusion and to answer your question, Yes! but NO. Aside from obvious browser limitations, it is far better to carry out calculations using server side code in the absence of JS.

编辑有关纯CSS的另一个简单示例,另请参见发疯的 Stu Nicholls 计算.

这篇关于可以用html/css进行简单的计算,但没有javascript或后端?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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