How to use HTML forms without a server

后端 未结 6 472
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-14 08:49

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

6条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-14 08:54

    Form elements can be used as a form of global variables - holding state that can be used and shared by all the javascript in a single page.

    However, this could result in brittle and difficult to understand code.

    I suggest keeping with passing parameters to functions, so long as you are in the context of a single page.

    If you need to pass data to another page, then forms can make life easier - using a GET form, the values on the form will be passed to the page referenced in the form action attribute as key-value pairs. If you use the POST method they will be transferred in the headers.

提交回复
热议问题