我应该如何构建隐私下拉(选择)菜单?

发布于 2024-08-27 09:42:38 字数 404 浏览 3 评论 0原文

我正在尝试构建类似于 Facebook 隐私选择菜单的东西,但没有“自定义”选项。它只会列出一些选项,例如“向所有人显示”、“仅向朋友显示”或“完全隐藏”。现在我正在考虑使用简单的 JavaScript 将隐藏输入字段更改为他们单击的新值,因此如果他们单击“仅向朋友显示”的分区,它将更改相应的字段,例如“email_privacy”, 1. 有没有更好的方法来做到这一点,或者我已经步入正轨了吗?

PS 我不打算使用选择元素,我计划使用 CSS 构建自定义下拉菜单,因为选择元素非常不可自定义。我这样做是为了节省空间,而不是在右侧放置大量的选择菜单,从而占用大量空间。

注意:我对使用 jQuery 并不是很感兴趣,那只是我不想加载的额外库和垃圾。我可以同样轻松地用 JavaScript 完成此操作,所以我也可以使用它。

I'm trying to build something similar to Facebook's privacy selection menu, except without the 'custom' option. It will only list a few options such as 'show to all', 'show to friends only', or 'completely hidden'. Right now I'm thinking of using simple JavaScript to change a hidden input field to the new value they click on, so if they clicked on the division for 'show to friends only' it would change the corresponding field, say 'email_privacy', to 1. Is there a better way to do this or am I pretty much on track?

P.S. I am not planning on using a select element, I was planning on building a custom drop-down menu using CSS since select elements are so highly non-customizable. I'm doing it this way to save space, rather than having this massive selection menu at the right which takes up a bunch of space.

Note: I'm not really interested in using jQuery, that's just extra libraries and crap that I don't want to load. I can do it in JavaScript just as easily so I might as well use that.

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

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

发布评论

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

评论(1

摇划花蜜的午后 2024-09-03 09:42:38

听起来你走在正确的轨道上。如果您打算在用户单击包含(除其他外)隐私值的提交按钮时执行 POST,那么您需要以某种方式将其打包在 POST 数据中,而隐藏字段是一种实现此目的的方法。

或者,如果您有兴趣使用 jQuery(我知道您说过您没有,只是把它放在那里),您可以执行异步 POST 请求并传递任意数据,例如本例中的隐私设置,而无需需要将其“复制”到隐藏字段中。

不过,这两个选项都工作得很好。

It sounds like you're on the right track. If you're planing on doing a POST when the user clicks the submit button containing (amongst other things) the privacy value, then you'll need to pack it in the POST data somehow, and a hidden field is a way to do it.

Alternatively if you were interested in making use of jQuery (which I know you said you weren't but just putting it out there) you can perform asynchronous POST requests passing along with it arbitrary data, such as in this instance the privacy setting, without needing to 'copy' it into a hidden field.

Both options work just fine though.

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