Twitter引导程序选择只读仍然可以更改选项 [英] Twitter bootstrap select readonly still able to change options

查看:111
本文介绍了Twitter引导程序选择只读仍然可以更改选项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用readonly="true"进行了引导选择,但是我仍然可以更改选择的选项.

I have a bootstrap select with readonly="true" but I can still change the selected option.

我需要disabled="true"行为,但是当我使用此行为时,未提交选择.

I need the disabled="true" behavior, but when I use this the select is not submitted.

我需要结合使用2,不能更改所选的选项,但必须提交所选内容.

I need a combination of the 2, the selected option can not be changed but the select has to be submitted.

我可以使用隐藏字段,但我希望有一个更简单的解决方案.

I could use hidden fields, but I was hoping for an easier solution.

推荐答案

另一种可能是使用带下拉菜单的select替换,应该可以禁用下拉菜单,但仍提交隐藏的select元素的值. 但是然后您也可以使用隐藏字段...

Another possibility could be to use a select replacement with dropdowns there it should be possible to disable the dropdown but still submitting the value of the hidden select element. But then you could also use hidden fields...

或者,如果选择元素被禁用,您确实可以添加一个具有选定值的隐藏字段.

Or you really add a hidden field with the selected value in case the select element is disabled.

<input type="hidden" name="whatever">
<select name="whatever">

如果隐藏字段与选择字段具有相同的名称,则选择字段的选定值应覆盖提交的隐藏字段值(例如,当使用js动态启用选择字段时).如果禁用了选择,则将发送隐藏字段的值. 不确定先提交的顺序.

If the hidden field has the same name as the select, the selected value of the select should overwrite the submitted value of the hidden field (e.g. when the select field is dynamically enabled with js). And if the select is disabled the value of the hidden field is sent. Not sure about the order of what is submitted first.

$(document).ready(function(){$('select option:not(:selected)').attr('disabled',true);});

此解决方案也应该起作用(至少在启用js的情况下).它禁用所有未选中的选项.因此,所选选项已提交,无法更改.

this solution should also work (at least with js enabled). It disable every not selected option. And therefore the selected option is submitted and it couldn't be changed.

有一个类似且已经回答的问题 html-form-readonly-select-tag -输入

这篇关于Twitter引导程序选择只读仍然可以更改选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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