What's the point of having hidden input in HTML? What are common uses for this?

后端 未结 12 1132
无人共我
无人共我 2020-12-01 14:51

I don\'t see the benefit of having hidden input? If you set the value of the hidden input why not just use that value at the point where you reference this hidden input?

12条回答
  •  时光取名叫无心
    2020-12-01 15:14

    It's just what it's name implies, a form input that is hidden from the user. It's a way of getting data to the server that the user doesn't need to see or control directly. This is especially useful for maintaining state.

    I'm working on a project right now where a user creates several items that are represented as data objects in JavaScript and serialized when sent to the server. These data items are expressed one way when displayed to the user with HTML, another way as JavaScript, and a third way when sent to the server. A hidden input is the only way to accomplish this. (Okay, fine not actually the only way, but certainly the most reasonable way).

提交回复
热议问题