送货区域的 Javascript 邮政编码表格?
我是一个 Javascript 菜鸟,下学期将参加课程并学习它,但与此同时,我有一个为本地企业做的基本网站。在它上面,我需要制作一个只有一个输入和一个提交按钮的表单,潜在客户可以在其中输入他们的邮政编码,它会说明他们是否在送货区域。我有大约 30 个邮政编码的列表。
有人可以指出我在哪里可以快速学习此功能的正确方向吗?我假设我只需要将这些 zip 输入到某个数组或类似的内容中,然后我就可以进行提交操作检查是否匹配。我理解逻辑,但我不知道从哪里开始编写代码,因为我目前只是一个 html/css 静态网页人员。
预先非常感谢。 戴夫
I'm a total Javascript noob and will be taking a class next semester and learning it but in the mean time, I have a basic website Im doing for a local business. On it I need to make a form with just one input and a submit button that a potential customer can enter their zip code into and it will say whether or not they are in the delivery area. I have a list of about 30 zip codes.
Can someone point me in the right direction of where to learn this functionality quickly? I assume I just need to type those zips into some array or something like that and then I have the submit action check for a match or not. I understand the logic but I have no idea where to begin with the code as I am currently just a html/css static webpage guy.
Thanks alot in advance.
Dave
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
要了解如何正确组装表单,请访问此网站。
然后,您可以将邮政编码数组存储在服务器上,并检查提交的代码是否在该数组中。如何执行此操作取决于您拥有的服务器设置。
要进行客户端验证,您可以设置它并签入 JavaScript。它会类似于:
Form:
JavaScript:
但是,永远不要仅仅依赖客户端验证。确保还执行服务器端验证。
To learn how to assemble your form correctly check out this web site.
Then you can have your array of zip codes on the server and check if the submitted code is in that array. How you do that will depend on what server setup you have.
To do client-side validation, you could set it up and check in the JavaScript. It would be something like:
Form:
JavaScript:
However, never rely solely on client-side validation. Make sure to also perform server-side validation.