一个输入字段,多个名称 [英] One input field, multiple names

查看:177
本文介绍了一个输入字段,多个名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在一个HTML表单中,我如何从一个输入字段获得两个名字?是否有可能通过隐藏的输入字段?如何?
我试图让隐藏的字段值动态地等于非隐藏的字段值(这样无论用户写什么,它们都是相等的),但我确定它不起作用,而不是像这样的东西会工作。 此处有人建议类似的应该是可能的。
我的问题应该在value属性中 - 我尝试了不同的值,但我没有设法将它绑定到foo值。

 < input name =fooid =footype =textvalue =foobar/> 
< input type =hiddenname =barid =barvalue = foo />

我更喜欢在没有Java Script的情况下解决它。



我想为不同的网站使用这两个属性,这些网站对同一个属性使用不同的名称(我们的目的相同,角色略有不同,但格式和值相同)。

解决方案

没有JavaScript,这是不可能的。就HTML而言,隐藏的输入字段只是静态数据;它们不受任何用户输入的影响。同样,当用户输入更改字段的值时,HTML中没有办法指定这也会更改另一个字段。



声明我想要为不同的网站使用同一属性的不同名称,似乎表明表单数据将被提交给两个或更多的服务器之一,具体取决于某些内容。尽管如果使用某些HTML5功能,这在技术上无法使用JavaScript,但其浏览器支持受到限制。可行的选项有:1)使用不同的形式,2)使用JavaScript,3)使用一个简单的服务器端调解器,根据数据中的某些字段将数据传递给一个或多个服务器端处理程序。 / p>

In a HTML form, how can I get two names from one input field? Is it possible through hidden input fields? And how? I tried to make the hidden field value dynamically equal to the non-hidden one (so that they will be equal no matter what the user writes), but I'm sure just that it doesn't work, not whether something like this would work. Here was suggested that something similar should be possible. My problem should be in the value attribute - I tried different values, but I didn't manage to bind it to the foo value.

<input name="foo" id="foo" type="text" value="foobar" />
<input type="hidden" name="bar" id="bar" value=foo />

I would prefer to solve it without Java Script.

I'd like to use both attributes for different websites, which use different names for the same property (the same for our purpose, the role is slightly different, but format and value is the same).

解决方案

It is not possible without JavaScript. Hidden input fields are just static data, as far as HTML is concerned; they are not affected by user input in any way. Similarly, when user input changes the value of a field, there is no way in HTML to specify that this would also change another field.

The statement "I’d like to use both attributes for different websites, which use different names for the same property" seems to suggest that the form data is to be submitted to one of two or more servers depending on something. Although this is technically possible without JavaScript if certain HTML5 features are used, their browser support is limited. The feasible options are: 1) Use different forms, 2) Use JavaScript, 3) Use a simple server-side mediator that passes the data forward to one or more server-side handlers depending on some field(s) in the data.

这篇关于一个输入字段,多个名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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