简体   繁体   English

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

[英]How should I build a privacy drop-down (select) menu?

I'm trying to build something similar to Facebook's privacy selection menu, except without the 'custom' option. 我正在尝试构建类似于Facebook的隐私选择菜单的东西,除了没有“自定义”选项。 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? 现在,我正在考虑使用简单的JavaScript将隐藏的输入字段更改为他们单击的新值,因此,如果他们单击“仅向朋友显示”的部门,则会更改相应的字段,例如“ email_privacy”,到1.是否有更好的方法可以做到这一点,或者我是否步入正轨?

PS 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. PS:我不打算使用select元素,我打算使用CSS构建自定义下拉菜单,因为select元素高度不可定制。 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. 注意:我对使用jQuery并不真正感兴趣,那只是我不想加载的额外的库和废话。 I can do it in JavaScript just as easily so I might as well use that. 我可以轻松地在JavaScript中完成此操作,因此我不妨使用它。

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. 如果您打算在用户单击包含(其中包括)隐私值的提交按钮时进行POST,则需要以某种方式将其打包在POST数据中,而隐藏字段是一种实现方式。

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. 另外,如果您有兴趣使用jQuery(我知道您不是说要把它放在那里),则可以执行异步POST请求,并随其传递任意数据,例如本例中的隐私设置,而无需需要将其“复制”到隐藏字段中。

Both options work just fine though. 两种选择都可以。

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

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