简体   繁体   English

html输入栏位选项

[英]html input field options

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 问候

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. 强制用户使用日期选择器的问题在于,除了使用HTML5表单输入外,您还不得不使用JavaScript来使选择器正常工作。 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. 如果禁用了JavaScript,那么您的用户将不得不手动输入该值,从而破坏了您最初放置在字段上的任何编辑保护。 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. 此外,将输入内容未经验证可能会使您容易遭受SQL注入攻击,在这种情况下,访问者使用其他工具(例如Firebug)通过输入手动发布未过滤的数据,并可能将其发布到数据库中。

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. 看,我知道表单验证是一件很麻烦的事,但是由于不想过滤它而试图锁定输入是麻烦的秘诀。

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 http://jqueryui.com/demos/datepicker/#icon-trigger

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM