jQuery .prop("disabled",false)未启用输入 [英] jQuery .prop("disabled", false) is not enabling an input

查看:396
本文介绍了jQuery .prop("disabled",false)未启用输入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

页面加载被禁用后,重新启用输入时出现问题.

I'm having a problem re-enabling an input after it has been disabled on the page load.

我正在使用两个输入来接受两个日期,但我希望第二个输入要等到第一个输入有值时才启用.

I'm using two inputs to accept two dates, but I want it that the second input is not enabled until the first one has a value.

<div id="date1" data-role="fieldcontain">
    <label for="date1-start" id="date1-startlbl">Start Date</label>
    <input name="date1-start" id="date1-start" type="date" data-role="datebox"data-options='{"mode": "calbox", "overrideDateFormat": "%Y-%m-%d", "beforeToday": true}' data-theme="a" onchange="showdate()"/>
    <label for="date1-end" id="date1-endlbl">End Date</label>   
    <input name="date1-end" id="date1-end" type="date" data-role="datebox" data-options='{"mode": "calbox", "overrideDateFormat": "%Y-%m-%d", "beforeToday": true}' data-theme="a" onchange="datechart()"/>
</div>

第二个输入在页面加载成功时被禁用.

The second input is disabled successfully on the page load with.

$("#date1-end").prop("disabled", true);

第一个日期有一个onchange事件,该事件调用以下函数

The first date has an onchange event that calls the following function

function showdate(){
    if ($("#date1-start").val() != null){
        if ($("#date1-end").val() != ""){
            datechart();
        }
        else{
            $("#date1-end").prop("disabled", false);
            $("#date1-end").trigger('change');
        }
    }
}

该函数被调用,并且prop("disabled", false)到达时将触发而没有任何错误,但是输入保持禁用状态.我正在使用的trigger('change')试图刷新元素,但是没有它也会存在相同的问题.

The function is called and prop("disabled", false) when reached fires without any errors, but the input remains disabled. The trigger('change') I am using is an attempt at refreshing the element but the same problem exists without it.

我尝试了与旧版本的Jquery不同的.attr变体,但我也遇到了同样的问题.

I have tried different variations of .attr from an older version of Jquery but I also get the same problem.

我正在使用Jquery 1.9.1,Jquery-mobile 1.3.1和PhoneGap 2.7.0

I am using Jquery 1.9.1, Jquery-mobile 1.3.1 and PhoneGap 2.7.0

推荐答案

工作示例: http://jsfiddle.net /d9vzs/

这不是启用禁用jQUery Mobile输入元素的方式.

This is not how you enable disable jQUery Mobile input elements.

可以使用以下功能完成

$( "input" ).textinput( "disable" );


$( "input" ).textinput( "enable" );

官方文档: http://api.jquerymobile.com/textinput/#method-禁用

这篇关于jQuery .prop("disabled",false)未启用输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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