jQuery-我可以验证禁用字段吗? [英] jQuery - can I validate a disabled field?

查看:59
本文介绍了jQuery-我可以验证禁用字段吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个表单,用户需要单击一个链接,然后通过一个弹出窗口选择一个用户,然后该窗口会填充一个具有ID的隐藏字段和一个具有用户名的显示字段.

I've got a form where the user needs to click a link, select a user via a popup window which then populates a hidden field with an ID and a display field with the username.

显示字段设置为disable ="disabled",以强制用户使用弹出窗口,而不在该字段中键入值.

The display field is set to disabled="disabled" to force the user to use the popup and not type a value in the field.

我需要确保用户选择一个名称.我正在使用jQuery和Jorn的验证插件.

I need to ensure the user selects a name. I'm using jQuery and Jorn's validation plugin.

执行必要的操作:如果该值为空白,则禁用字段上的true似乎不会触发.

Doing a required: true on the disabled field doesn't seem to fire off if the value is blank.

任何想法如何解决这个问题?

Any ideas how to solve this?

推荐答案

不是将其禁用,而是尝试将其设置为只读吗?

Instead of making it disabled, have you tried making it readonly?

<input type="text" readonly="readonly" />

我记得几年前,禁用字段不是由表单提交的,因此很可能没有经过验证

I remember from years ago that disabled fields are not submitted by forms, and hence probably are not validated

这是 W3C HTML4规范主题.

这篇关于jQuery-我可以验证禁用字段吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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