html 输入字段选项
我有一个输入字段,单击该输入字段后,我将显示一个日期选择器来选择日期。我希望始终从该选择器中选择该字段,而不是通过键入。原因是,我只是修改这一字段,不想修改整个代码来验证该字段。我已经为用户提供了足够的下拉选项,以便他们从下拉列表中进行选择,因此我更喜欢使用此选择而不是通过键入来接受输入。如果我允许输入,用户有可能将年份更改为过去的一年,这会覆盖所有内容。
问候
I have a input field and on clicking that I will show a date picker to select the date. I would like to always make this field select using from that picker and not by typing. the reason is, i am just modifying this one field and don't want to touch the whole code to validate this field. i have given enough drop down options for the users to select from the drop down so i prefer to accept input using this selection and not by typing. if i allow typing , there are chances that users can change the year to a past year and that overrides everything.
regards
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
强制用户使用日期选择器的问题在于,如果不使用 HTML5 表单输入,您就被迫使用 JavaScript 来使选择器工作。如果 JavaScript 被禁用,那么您的用户将必须手动输入值,从而破坏您首先在字段上设置的任何编辑保护。无论如何,该输入都必须经过验证。
此外,未经验证的输入可能会让您容易受到 SQL 注入攻击,访问者使用其他工具(例如 Firebug)通过该输入手动发布未经过滤的数据,并可能将其发布到您的数据库中。
看,我知道表单验证很痛苦,但尝试锁定您的输入,因为您不想过滤它,这会带来麻烦。
The problem with forcing users to use a date picker is that, short of using HTML5 form inputs, you're forced to use JavaScript to make the picker work. If JavaScript is disabled, then your user will have to input the value by hand, defeating whatever edit protection you put on the field in the first place. That input would have to be validated anyway.
In addition, leaving your input without validation could leave you vulnerable to SQL injection attacks, where a visitor uses some other tool (like Firebug, for instance) to manually post unfiltered data through that input and possibly into your database.
Look, I know form validation is a pain, but trying to lock down your input because you don't want to filter it is a recipe for trouble.
您可以尝试使用日期选择器的按钮,并在选择日期时设置隐藏字段和可见标签。
查看其中及其周围的一些示例:
http://jqueryui.com/demos/日期选择器/#icon-trigger
you could try using a button for the datepicker and on selection of a date set a hidden field and a visible label.
Look at some of the examples in and around this:
http://jqueryui.com/demos/datepicker/#icon-trigger