构建类来构造表单输入元素

发布于 2024-11-16 07:49:53 字数 1459 浏览 2 评论 0原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

倾城花音 2024-11-23 07:49:53

我认为如果您还想将输入对象与其他对象绑定在一起,这可能是一个好方法。就像验证/消息响应一样,验证对象将数据传递给输入助手。这应该允许以“简单”的方式在表单中提供一些用户功能。

如果您希望在某个时候将一些其他功能合并到此类中,并且您只想输出一些 HTML,并且担心性能,那么您应该直接将其键入。

建议

按照你目前的策略,你最终会一遍又一遍地复制很多东西。当您想要创建password 输入或textarea 时,您最终会复制大量相同的变量!

您可以做的替代方案是创建一个表单生成器对象可以扩展的类,该类为适当类型的 HTML 元素提供一些通用功能/属性。显然,如果不了解您想要做什么以及如何做的更大蓝图,我什至无法开始告诉您如何将其纳入您自己的策略中。

I think that this could be a good approach if you're wanting to also tie your input objects in with something else. Like say, a validation/message response where your validation object passes data off to your input helper. This should allow an 'easy' way to provide some user functionality in your forms.

If you aren't looking to incorporate some other functionality into this class at some point and you just want to spit out some HTML, and are worried about performance, you should just type it out raw.

A suggestion

With your current strategy you're gonna wind up copying a lot of things over and over. When you want to create a password input or a textarea you'll wind up copying a lot of these same variables!

What you could do as an alternative is create a class that your form generator objects can extend from that provide some general functionality/properties for the appropriate types of HTML elements. Obviously I couldn't even begin to tell you how to incorporate this into your own strategy without knowing a bigger picture of what you're trying to do and how you're trying to do it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文