我有一个表单,我必须将表单值发布到我的动作类.在这种形式中,我有一个需要只读的复选框.我尝试过设置,disabled="true"但在发布到动作类时不起作用.
所以请指教?
假设我有以下HTML:
<form id="myform">
<input type='checkbox' name='foo[]'/> Check 1<br/>
<input type='checkbox' name='foo[]' checked='true'/> Check 2<br/>
<input type='checkbox' name='foo[]'/> Check 3<br/>
</form>
Run Code Online (Sandbox Code Playgroud)
现在,如何选择名为'foo []'的已检查输入字段?
这是我的尝试,但它不起作用:
$("#myform input[name='foo']:checked:enabled");
Run Code Online (Sandbox Code Playgroud) 我有一个CheckBoxList控件,我想让用户检查至少一个盒子,如果他们检查每一个,或3个,甚至只是一个,都没关系.
本着asp.net的验证控件的精神,我可以使用什么来强制执行此操作?我也在使用Ajax验证扩展器,所以如果它看起来像其他控件,而不是代码隐藏中的一些俗气的服务器验证方法,那将会很好.
<asp:CheckBoxList RepeatDirection="Horizontal" RepeatLayout="Table" RepeatColumns="3" ID="ckBoxListReasons" runat="server">
<asp:ListItem Text="Preliminary Construction" Value="prelim_construction" />
<asp:ListItem Text="Final Construction" Value="final_construction" />
<asp:ListItem Text="Construction Alteration" Value="construction_alteration" />
<asp:ListItem Text="Remodel" Value="remodel" />
<asp:ListItem Text="Color" Value="color" />
<asp:ListItem Text="Brick" Value="brick" />
<asp:ListItem Text="Exterior Lighting" Value="exterior_lighting" />
<asp:ListItem Text="Deck/Patio/Flatwork" Value="deck_patio_flatwork" />
<asp:ListItem Text="Fence/Screening" Value="fence_screening" />
<asp:ListItem Text="Landscape - Front" Value="landscape_front" />
<asp:ListItem Text="Landscape - Side/Rear" Value="landscape_side_rear" />
<asp:ListItem Text="Other" Value="other" />
</asp:CheckBoxList>
Run Code Online (Sandbox Code Playgroud) 我有一个Django应用程序,并希望在用户的配置文件中显示多个选项复选框.然后他们将能够选择多个项目.
这是我的models.py的简化版本:
from profiles.choices import SAMPLE_CHOICES
class Profile(models.Model):
user = models.ForeignKey(User, unique=True, verbose_name_('user'))
choice_field = models.CharField(_('Some choices...'), choices=SAMPLE_CHOICES, max_length=50)
Run Code Online (Sandbox Code Playgroud)
我的表格类:
class ProfileForm(forms.ModelForm):
choice_field = forms.MultipleChoiceField(choices=SAMPLE_CHOICES, widget=forms.CheckboxSelectMultiple)
class Meta:
model = Profile
Run Code Online (Sandbox Code Playgroud)
和我的views.py:
if request.method == "POST":
profile_form = form_class(request.POST, instance=profile)
if profile_form.is_valid():
...
profile.save()
return render_to_response(template_name, {"profile_form": profile_form,}, context_instance=RequestContext(request))
Run Code Online (Sandbox Code Playgroud)
我可以看到POST只发送一个值:
choice_field u'choice_three'
Run Code Online (Sandbox Code Playgroud)
当地的vars params正在发送一份清单:
[u'choice_one', u'choice_two', u'choice_three']
Run Code Online (Sandbox Code Playgroud)
所有表单字段都显示正确,但是当我提交POST时,我收到错误
错误绑定参数7 - 可能不受支持的类型.
我是否需要在视图中进一步处理多选字段?模型字段类型是否正确?任何帮助或参考将不胜感激.
好奇当用户检查多个复选框(具有相同的名称值)时处理情况的"轨道方式",并将其发布回控制器.
您如何检查是否选择了多个项目,然后在ID值上进行拆分等.
我已经看到了预选复选框的三种实现方式.我开始使用checked ="checked",因为我认为这是"正确"的方式(从来没有像"checked"="是"那样).我正在考虑更改为checked ="true",因为它似乎更易读并且更容易编写JavaScript代码.请注意,同样的问题适用于其他属性,例如"disabled"="disabled"与"disabled"="true".只要我一致,使用"真实"的首选方法?谢谢
<input type="checkbox" checked="checked" value="123" name="howdy" />
<input type="checkbox" checked="true" value="123" name="howdy" />
<input type="checkbox" checked="yes" value="123" name="howdy" />
Run Code Online (Sandbox Code Playgroud) 更新:对于最新的Angular版本,问题已经过时,请参阅tsh对此帖子的评论
我已将一个复选框绑定到一个值:
<input type="checkbox" ng-model="checkbox" ng-true-value="1" ng-false-value="0" />
Run Code Online (Sandbox Code Playgroud)
控制器中复选框的值设置为1:
function Controller($scope) {
$scope.checkbox = 1
}
Run Code Online (Sandbox Code Playgroud)
但是,最初复选框似乎未选中.如果我将$scope.checkboxto 的初始值更改为"1",则确实如此.(jsfiddle演示)
我尝试了各种变化:
ng-true-value="{{1}}"
ng-true-value="{{Number(1)}}"
ng-true-value="{{parseInt('1')}}"
Run Code Online (Sandbox Code Playgroud)
他们都没有工作.如何将参数作为数字进行角度处理?
Checkboxes在HTML表单中没有隐含的标签.在它旁边添加显式标签(一些文本)不会切换checkbox.
如何通过单击文本标签来切换复选框?
我被要求禁用复选框的"滴答".我没有被要求禁用该复选框,而只是禁用"滴答".
换句话说,用户会认为复选框是可勾选的,但事实并非如此.相反,单击该复选框将显示模式对话框,为用户提供更多选项以打开或关闭复选框所代表的功能.如果在对话框中选择的选项导致打开该功能,则会勾选该复选框.
现在,真正的问题是,只需一瞬间,您仍然可以看到勾选了复选框.
我尝试过这样的方法:
<input type='checkbox' onclick='return false' onkeydown='return false' />
$('input[type="checkbox"]').click(function(event) {
event.preventDefault();
alert('Break');
});
Run Code Online (Sandbox Code Playgroud)
如果你运行这个,会出现警报,显示勾号是可见的(警报只是为了证明它仍然被勾选,在生产中,警报不存在).在一些使用较慢机器的用户和/或使用慢速渲染器/ javascript的浏览器中,用户可以看到非常微弱的闪烁(闪烁有时持续半秒,这是显而易见的).
我的团队中的测试人员已将此标记为缺陷,我应该修复它.我不知道还有什么可以阻止复选框中的勾号闪烁!
我在这里广泛搜索了一个答案,但还没有找到我正在寻找的东西.找到这个CSS - 如何设置所选单选按钮标签的样式?但答案涉及更改标记,这是我想要避免的内容,我将在下面解释.
我正在尝试为我的XenForo论坛主题添加自定义css3复选框和单选按钮,我读过的所有教程在输入后都有标签:
<input type="checkbox" id="c1" name="cc" />
<label for="c1">Check Box 1</label>
Run Code Online (Sandbox Code Playgroud)
但是在XenForo的标记中,输入位于标签内:
<label for="ctrl_enable_rte">
<input type="checkbox" name="enable_rte" value="1" id="ctrl_enable_rte" {xen:checked "{$visitor.enable_rte}"} />
{xen:phrase use_rich_text_editor_to_create_and_edit_messages}
</label>
Run Code Online (Sandbox Code Playgroud)
我查看了为什么会这样,但是当标记是这样时,没有找到任何与自定义css复选框/单选按钮相关的内容.我想避免不得不改变标记,因为我在这里处理一个论坛系统,这将涉及编辑一堆核心模板......我必须在每次论坛软件时更新标记推出更新(假设模板已更改).
我已经尝试创建可以使用这种类型标记的CSS规则,但到目前为止我还没有成功.我对CSS没有太多经验,没有记住每一个选择器,伪类对我来说仍然很陌生,所以我希望这里有人能说明这是否可行,如果可行的话,我怎么样可能会去做.我已经准备好了我的精灵,我只需要弄清楚CSS了.
我的主要问题是我无法弄清楚如何选择标签(当然只有与这些输入有关的标签).通常是这样的
input[type="checkbox"] + label
Run Code Online (Sandbox Code Playgroud)
使用,但当标签不是在输入之后而是在它之外/之前...如何选择它?
checkbox ×10
javascript ×3
html ×2
input ×2
.net ×1
angularjs ×1
asp.net ×1
checkboxlist ×1
css ×1
django ×1
html-input ×1
jquery ×1
label ×1
python ×1
radio-button ×1
select ×1
validation ×1