javascript - 除非选中,否则禁用日期输入,然后设为必填
问题描述
我正在处理以下表格,其中包含以下可供选择的选项值。如果选择了选项值“下面列出的以下时间段或访问日期的有限授权”,expdate
则可以填写该字段。但是,我想让他们expdate
填写必填字段。我怎样才能做到这一点?我非常感谢任何意见或建议,因为我在这方面没有受过任何教育,只是通过玩来学习............
<![CDATA[
<script type="text/javascript">
function $enableRequiredTextField($field) {
$field.val("");
$field.prop({"readonly": false,"tabIndex":0});
$field.removeAttr('style');
}
function $disableRequiredTextField($expdate) {
$field.val("N/A");
$field.prop({"readonly": true,"tabIndex":-1});
$field.css({"background-color": "#DDDDDD"});
$field.removeClass("alertborder");
}
$('#authorize').change(function() {//on change of select
$('#expdate', ).prop('disabled', $('option:selected', this).val() != 'Limited authorization for the following time period or visit date(s) listed below');
//check if value is not Limited authorization for the following time period or visit date(s) listed below then disable
}).change();//call on change manually so on load will run the change event
<inputField name="authorize" type="combo" prompt="Select an option from the drop down list:">
<options>
<option selected="true" />
<option value="My authorization is not limited to a certain time period or visit date">My authorization is not limited to a certain time period or visit date</option>
<option value="This authorization shall be in effect for 12 months following the date of signature">This authorization shall be in effect for 12 months following the date of signature</option>
<option value="Limited authorization for the following time period or visit date(s) listed below">Limited authorization for the following time period or visit date(s) listed below</option>
</options>
</inputField>
<inputField name="expdate" type="date" required="true" prompt="Date Authorized Until:" />
<inputField name="mustCheck" type="checkbox">
<options>
<option value="true">I understand that this authorization will remain in effect until such time that I revoke it in writing.</option>
</options>
</inputField>
</inputFields>
<text type="submit" class="completeworkflow">Submit Request</text>
解决方案
看看附图,我认为您指的是“mustCheck”对吗?尝试使用 name="mustCheck" 将 required 添加到 inputField。
<inputField name="mustCheck" type="checkbox" required>
html也有一个名为“disabled”的属性,所以
<inputField name="expdate" type="date" required="true" disabled="true" prompt="Date Authorized Until:" />
如果您想使用 JavaScript 启用该元素
document.getElementById('expdate').disabled = false;
如果你使用 jQuery
$('#expdate').prop('disabled', false);
推荐阅读
- sql - 查找特定事件之前的最新事件
- ruby - Nokogiri 不会打印,page.css 没有返回任何内容
- python-3.x - “while True”循环内的线程
- reactjs - 图像路径正在转换为数据 URI 而不是 URL
- javascript - 如何在我的代码 nuxtjs 上导入外部 js 和 css
- php - WordPress 自定义主题上的父子标题
- python - 了解 `np.ndarray` 子类化中的默认值
- javascript - Python Web Scraper - 由页面 JavaScript 定义的每个页面的有限结果
- jquery - 可访问的展开/折叠表格行
- python - 以下代码的算法或性能改进