如何在没有服务器的情况下使用HTML表单 [英] How to use HTML forms without a server

查看:180
本文介绍了如何在没有服务器的情况下使用HTML表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不是网络开发人员,并且想要了解更好的方法来传递变量。在过去,我使用各种方式将事情传递给Java脚本函数。我从来没有使用表单,因为我总是将它们与服务器和数据库关联起来我有一个网站,其中用户选择更改网站的内容。

我想知道,如果你可以使用没有任何服务器的表单,只是将一些东西传递给一个用于改变页面内容的javascript函数的方法。对于基本的例子,如果有人选择男性,页面背景变成蓝色,如果他们选择女性,背景变成粉红色。表单将成为去的方式,只是onsubmit调用一个JavaScript函数?我怎样才能将表单内容传递给javascript函数?

解决方案

是的,您绝对可以使用表单/输入/任何类型html元素,从不与服务器通话,只是不希望存储该数据!你正确地使用事件(比如你提到的onsubmit)来触发Javascript函数。



这是一个快速而脏的例子按照你的意愿去做。请注意,不是在颜色变化之前等待表单提交,而是在他们从下拉列表中选择性别后立即执行。



http://jsfiddle.net/wG8K4/1/


I am not a web-developer and want to understand the better way to pass variables. In the past I have used various ways to pass things to java script functions. I have never used forms as I always associated them with server and databases. I have a website in which user selections change the contents of the website.

I am wondering if you can use forms without any server just as a way to pass a few things to a javascript function where they are used to change the page content. For basic example, if someone selects male the page background becomes blue, if they choose female the background becomes pink. Would forms be the way to go and just onsubmit call a javascript function? How would I actually pass the form contents to the javascript function?

解决方案

Yes you absolutely can use forms/inputs/any kind of html element and never talk to a server, just don't expect to store that data! You're right about using events (like the onsubmit one you mentioned) to trigger Javascript functions.

Here is a quick and dirty example (heavy on the dirty) that does sorta kinda what you'd like. Note that instead of waiting for the form to be submitted before the color change, I go ahead and do it immediately after they choose a gender from the dropdown.

http://jsfiddle.net/wG8K4/1/

这篇关于如何在没有服务器的情况下使用HTML表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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