当“下拉列表选择"字段设置为某个值时,清除文本输入字段吗? [英] Clear a text input field when a DropDown Selection field is set to a certain value?

查看:93
本文介绍了当“下拉列表选择"字段设置为某个值时,清除文本输入字段吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据下面的HTML选择表单字段,我需要重置当选择字段被设置为任何值,除了

Based on the HTML Selection form field below, I need to reset a text field value when the selection field is set to any value besides Completed or Cancelled

<select name="status" id="status" title="">
    <option label="Open" value="Open">Open</option>
    <option label="In Progress" value="In_Progress">In Progress</option>
    <option label="Future_Project" value="Future_Project">Future_Project</option>
    <option label="Cancelled" value="Cancelled">Cancelled</option>
    <option label="Completed" value="Completed" selected="selected">Completed</option>
</select>

我需要将值设置为空/无的文本输入看起来像这样...

The Text input that I need to set the value to empty/nothing looks like this...

<input autocomplete="off" type="text" id="date_completed_date" value="09/20/2014 06:15pm" size="11" maxlength="10" onblur="combo_date_completed.update();" onchange="combo_date_completed.update(); ">

我可以使用jQuery或常规JavaScript.我将不胜感激,我认为这应该很简单?

I can use jQuery or regular JavaScript. I would appreciate any help, I think this should be pretty simple?

推荐答案

如果用户重新选择另一个选项,则值得保留日期,否则日期将保留为空白.

Its worth retaining the Date if the user Re-selects another Option otherwise the date will stay Blank.

var date = $('#date_completed_date').val();
$("select").on("change", function () {

    if ($(this).val().indexOf('ed') == -1) {
   $('#date_completed_date').val('');
}
    else { 
        $('#date_completed_date').val(date); 
    }

})

演示

http://jsfiddle.net/mrw9hor8/

这篇关于当“下拉列表选择"字段设置为某个值时,清除文本输入字段吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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