如何使用“选择"字段突出显示必填字段插入? [英] How I can highlight as required field with "chosen" Plugin?

查看:150
本文介绍了如何使用“选择"字段突出显示必填字段插入?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面是下拉代码,我想要此字段为必填字段,但没有检查验证内容.

Following dropdown code and I want to this field as required but there is no checking for validation.

<select id="mood" rel="chosen" required="required" name="moodName">
<option value="">Select Option</option>
<option value="69">AGITATED</option>
<option value="115">ALOOF</option>
<option value="46">AMUSED</option>
</select>

验证码

$('#Form').validate();

在提交表单时如何验证所选字段的必填字段?例如此字段为必填字段" .

How to validate as required field of chosen field when Submit form? like "This field is required".

推荐答案

我最终使用了 https://github.com/harvesthq/chosen/issues/2075#issuecomment-193805605

也就是说,在chosen.jquery.js中找到这样的行

That is, find the line in chosen.jquery.js that says

this.form_field_jq.hide().after(this.container);

并替换为

this.form_field_jq.css('position', 'absolute').css('opacity', 0).after(this.container);

隐藏" select元素而不是告诉浏览器隐藏它是一种黑客.因此,Chrome在需要显示请在列表中选择一个项目"消息时将能够找到该元素.

It is a hack to "make invisible" the select element instead of telling the browser to hide it. Hence Chrome will be able to find the element when it needs to show the "please select an item in the list" message.

这篇关于如何使用“选择"字段突出显示必填字段插入?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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