如果input标签没有名字,表单数据是否仍然传输?

为了提高效率,我想知道如果你省略了name属性或者将其设置为null,textarea中的文件或者文本是否仍然被传送到服务器。 例如

<input type="file" id="file" name=""> <textarea id="text" name=""> 

我注意到,如果你这样做,服务器上的数据是不可用的。

如果我理解正确,W3C规范要求每个表单input元素都有一个指定的name属性。 否则,该元素将不会被处理。 资源

没有。

我在所有的浏览器中都检查过 – 在浏览器的POST / GET请求中缺less空/缺less名字的字段。 不pipe他们是否有id(我的想法是浏览器可能使用id而不是id)。

它不会直接工作,但你可以通过JavaScript中的AJAX调用来分配它们,idk真的知道这是否真的在真实世界中有任何应用程序(可能是服务器期望的参数混淆)

 <form id="login" method="post" action="someurl"> <input id="username" type="text" /> <input id="password" type="password" /> <input type="submit" value="login" /> </form> 

JS来处理将(使用jQuery来处理Ajax)

 $("#login").on("submit",function(ev){ $.post("someurl",{ usrn: $("#username").val, pwd: $("#password").val },function(ev){ //this is the callback function that runs when the call is completed successfully }); } /*second argument on $.post is and object with data to send in a post request usrn would be the name of the parameter recived in the server same for pwd "#username" and "#password" are the id's html attribute for the field '.val' is the jquery object's attribute in which jquery access the value in the text box "$()" or it's equivalent "jQuery()" works like an object constructor that fills the attributes with the DOM data that cover the css selector that this function expects as a parameter*/ 

请注意代码可能不完全正确,因为我没有testing它,但它背后的逻辑应该是不言自明的