【问题标题】:How to disable a text field when there is a select drop down selected选择下拉列表时如何禁用文本字段
【发布时间】:2014-03-29 20:41:12
【问题描述】:

我在互联网上搜索了一段时间,但找不到我想要的。

How to disable a text field when there is a select drop down selected with value (not emtpy)?

另外,切换它会很好。如果在“选择”下拉(无值)中没有选择选项时,则用户可以在文本字段中键入

我发现了一些类似的代码,但它在这里检查值是否等于“/\Custom\b/gi”我希望它检查是否选择了某些东西?

$('#Select_Font, #Enter_Text').attr('disabled', 'disabled');
$('.dropdownstyle').change(function () {

    var present = $(this).val().match(/\Custom\b/gi) == null ? true : false;
        if(present){
            $('#Select_Font, #Enter_Text').attr('disabled', 'disabled');
        }
        else{
            $('#Select_Font, #Enter_Text').removeAttr('disabled');
        }
});

来源:How to enable or disable drop-down or text-box on selection other drop-down?

这可能吗?提前致谢。

编辑:

html

<div class='row'>
    <div class="large-6 columns">
        <label for="group">Group

            <select name="selectGroup" id="selectGroup">
                <option value="">Choose a group</option>

                <?php
                while ($row = $result->fetch_assoc()) {
                    echo '<option value="' . $row['group'] . '">' . $row['group'] . '</option>';
                }
                ?>

            </select>
        </label>
    </div>

    <div class="large-6 columns">
        <label for="group">Or make a new group
            <input type="text" name="makeGroup" id="makeGroup"/>
        </label>
    </div>
</div>

【问题讨论】:

  • 相关的 HTML 是什么?

标签: javascript jquery html css


【解决方案1】:
$('#selectGroup').change(function () {
    $('#Select_Font, #Enter_Text').prop('disabled', this.value.length);
});

FIDDLE

【讨论】:

  • 当您在文本字段中输入了一些值并选择了一个组(选项)时,该值仍在文本字段中,我使用了 $('#textCategorie').removeAttr('value');但这没有用
  • 这是一个你并没有真正问过的无关问题,但你会这样做 -> jsfiddle.net/adeneo/9reSb/5
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-06-26
  • 1970-01-01
  • 2019-05-19
  • 2018-08-27
  • 1970-01-01
相关资源
最近更新 更多