search
Homephp教程php手册Selcect表单取值运算的两种方法

这几天略忙没怎么折腾,今天研究了一下用select表单取值进行运算的方法,感觉JS版不是什么新鲜玩意儿,但PHP版本好像还没见人写过,所以一起写出来顺便除除草. 我是边吃饭边写的,写完我就吃完了,吃完我就出去了,最近没有时间一个个看评论,大概得等什么时候我状态

这几天略忙没怎么折腾,今天研究了一下用select表单取值进行运算的方法,感觉JS版不是什么新鲜玩意儿,但PHP版本好像还没见人写过,所以一起写出来顺便除除草.
我是边吃饭边写的,写完我就吃完了,吃完我就出去了,最近没有时间一个个看评论,大概得等什么时候我状态好点才会回复了吧.
希望你们还是那么深深的思念我.

PHP法

PHP需要通过$_POST获取由表单提交传过来的值,所以需要点击按钮提交后才能实现运算,


x 2 =

效果如下:

x 2 = 2

JS法

JS法无需刷新页面,会实时显示结果


x 2 = 2
<script> function getResult(){ var number = document.formJs.xhdSelect.value;//获取select值 document.getElementById("result").innerHTML= number*2;//重写元素显示运算结果 } </script>

效果如下:

x 2 = 2

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools