防止表单中的值传递

时间:2021-05-28 00:03:56

I have 4 <select></select> elements in my form. Usually when submitting the form you would get this in the url, e.g.

我的表单中有4个

index.html?day=01&month=01&year=1999&reporter=Joe+Blogs

However in my interface users are switching between the date picker and the person picker. Is it possible to only send the values on the select that is active?

但是在我的界面中,用户正在日​​期选择器和人员选择器之间切换。是否可以仅在激活的选择上发送值?

[I started writing this to post to you guys but then I had a thought and checked out the disabled attribute of form elements - so in the spirit of stack over flow I have entered my own answer too]

[我开始写这篇文章给你们发帖,但后来我有一个想法并检查了表单元素的禁用属性 - 所以本着堆栈溢出的精神我已经输入了我自己的答案]

5 个解决方案

#1


0  

Why you disable this in javascript though?

为什么你在javascript中禁用它?

You should make a server-side decision anyway, what if server gets the both person and date parameters (e.g. someone who has javascript disabled or just jquery blocked...)

无论如何,您应该做出服务器端决策,如果服务器获取了人员和日期参数(例如,禁用了javascript或仅阻止了jquery的人),该怎么办?

#2


1  

Use the .attr("disabled","disabled") in jQuery.

在jQuery中使用.attr(“disabled”,“disabled”)。

#3


1  

You could put the date picker and the name selection in separate forms (possibly with separate "Action=... 's).

您可以将日期选择器和名称选择放在不同的表单中(可能使用单独的“Action = ...”)。

Simple and works on any browser.

简单,适用于任何浏览器。

#4


1  

yeah - after I did this I realised the problem I had created for non-js users. I have made a "todo" to break it up into two forms. I thought I was being smart by turning on and off different fieldsets (trying to use proper markup) but then, yeah, stuffed that up. Oh well, least I learned about disabled and how to manipulate it in jQuery...

是的 - 在我这样做之后,我意识到我为非js用户创建的问题。我已经做了一个“todo”将它分解为两种形式。我认为通过打开和关闭不同的字段集(尝试使用适当的标记)来表现得很聪明,但是,然后,是的,把它填满了。哦,至少我了解了禁用以及如何在jQuery中操作它...

#5


0  

I would rather prefer to pass the control to the server side for any sort of validation.

我宁愿将控件传递给服务器端进行任何类型的验证。

#1


0  

Why you disable this in javascript though?

为什么你在javascript中禁用它?

You should make a server-side decision anyway, what if server gets the both person and date parameters (e.g. someone who has javascript disabled or just jquery blocked...)

无论如何,您应该做出服务器端决策,如果服务器获取了人员和日期参数(例如,禁用了javascript或仅阻止了jquery的人),该怎么办?

#2


1  

Use the .attr("disabled","disabled") in jQuery.

在jQuery中使用.attr(“disabled”,“disabled”)。

#3


1  

You could put the date picker and the name selection in separate forms (possibly with separate "Action=... 's).

您可以将日期选择器和名称选择放在不同的表单中(可能使用单独的“Action = ...”)。

Simple and works on any browser.

简单,适用于任何浏览器。

#4


1  

yeah - after I did this I realised the problem I had created for non-js users. I have made a "todo" to break it up into two forms. I thought I was being smart by turning on and off different fieldsets (trying to use proper markup) but then, yeah, stuffed that up. Oh well, least I learned about disabled and how to manipulate it in jQuery...

是的 - 在我这样做之后,我意识到我为非js用户创建的问题。我已经做了一个“todo”将它分解为两种形式。我认为通过打开和关闭不同的字段集(尝试使用适当的标记)来表现得很聪明,但是,然后,是的,把它填满了。哦,至少我了解了禁用以及如何在jQuery中操作它...

#5


0  

I would rather prefer to pass the control to the server side for any sort of validation.

我宁愿将控件传递给服务器端进行任何类型的验证。