禁用< option>当已经选择 [英] Disable an <option> when already selected

查看:64
本文介绍了禁用< option>当已经选择的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果有人已经使用该选项提交了表单,如何禁用该选项。

How do I disable an option if someone already submits the form with that option.

<select>
    <option value="1">Session 1</option>
    <option value="2">Session 2</option>
    <option value="3">Session 3</option>
</select>

例如,如果用户选择了会话2,我不希望它可用当其他人尝试提交表单时。我只希望每个会话有1个用户。

For instance if session 2 has been selected by a user, I don't want it to be available when someone else tries to submit the form. I only want to have 1 user per session.

谢谢!

推荐答案

我同意Serlite的评论。仅使用Javascript几乎是不可能的。您必须使用PHP之类的后端服务器语言。如果您使用PHP,则可以为每个选项指定一个ID,并且如果该选项先前已提交(您可以将其传递给PHP或将该信息存储在数据库中),请停用该选项。我将需要更多地了解您实际上想为您提供一个代码段的方法。例如,表格的用途是什么?您是否正在将其提交到数据库?等等

I agree with Serlite's comment. It's nearly impossible to do it purely with Javascript. You'd have to use a back-end server language like PHP. If you used PHP, you could give each option an id, and if that option has been previously submitted, (which you could pass in PHP or store that information in a database), make that option deactivated. I'd have to know more about what exactly you're trying to do to actually give you a code snippet. For example, what is the form used for? Are you submitting it to a database? etc.

这篇关于禁用&lt; option&gt;当已经选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆