Javascript 显示错误的jQuery大纲文本字段

Javascript 显示错误的jQuery大纲文本字段,javascript,jquery,Javascript,Jquery,我有一个textfield,当textfield没有包含三个字符时,我禁用了提交按钮。我现在想做的是勾勒出文本字段粗体红色,并且仍然禁用了提交按钮,但是我似乎无法勾勒出文本字段并同时禁用提交按钮 我禁用提交按钮的代码如下:当此功能中的长度

我有一个
textfield
,当
textfield
没有
包含三个字符时,我禁用了提交按钮。我现在想做的是勾勒出
文本字段
粗体红色,并且仍然禁用了
提交
按钮,但是我似乎无法勾勒出
文本字段
并同时禁用提交
按钮

我禁用提交按钮的代码如下:当此功能中的
长度<3
时,是否可以概述
文本字段

谢谢你的帮助

$(function() {

        $('input[name="updateMessage"]').attr('disabled','disabled');
        $('input[name="selectMessageForUpdate"]').keyup(function(){
            if($('input[name="selectMessageForUpdate"]').val().length < 3)
            {
                $('input[name="updateMessage"]').attr('disabled','disabled');
            }
            else
            {
                $('input[name="updateMessage"]').removeAttr('disabled');
            }
        });

    });
$(函数(){
$('input[name=“updateMessage”]”)。attr('disabled','disabled');
$('input[name=“selectMessageForUpdate”]”)。键控(函数(){
if($('input[name=“selectMessageForUpdate”]').val().length<3)
{
$('input[name=“updateMessage”]”)。attr('disabled','disabled');
}
其他的
{
$('input[name=“updateMessage”]”)。removeAttr('disabled');
}
});
});

添加
边框
css属性以及
attr('disabled')

在css中添加一个类来定义红色边框:

textarea[name=selectMessageForUpdate].disabled { border:5px solid red }
input.indicated_textfield { border: 2px solid red; }
你的js:

$(function() {

        $('input[name="updateMessage"]').attr('disabled','disabled');
        $('textarea[name="selectMessageForUpdate"]').keyup(function(){
            if($(this).val().length < 3)
            {
                $('input[name="updateMessage"]').attr('disabled','disabled');
                $(this).addClass('disabled'); // ADD THIS
            }
            else
            {
                $('input[name="updateMessage"]').removeAttr('disabled');
                $(this).removeClass('disabled'); // ADD THIS
            }
        });

    });
$(函数(){
$('input[name=“updateMessage”]”)。attr('disabled','disabled');
$('textarea[name=“selectMessageForUpdate”]”)。keyup(函数(){
if($(this).val().length<3)
{
$('input[name=“updateMessage”]”)。attr('disabled','disabled');
$(this.addClass('disabled');//添加此
}
其他的
{
$('input[name=“updateMessage”]”)。removeAttr('disabled');
$(this.removeClass('disabled');//添加此
}
});
});
我创造了一个js小提琴,它似乎工作


他想要的是文本区域的样式,而不是提交按钮。只需使用指定的标记向textarea添加一个类,并在输入有效时将其删除。还要检查输入是否不仅仅是空白

$(function() {
    $('input[name=updateMessage]').attr('disabled','disabled');
    $('input[name=selectMessageForUpdate]').keyup(function(){
        if($('input[name=selectMessageForUpdate]').val().length < 3)
        {
            $('input[name=updateMessage]').attr('disabled','disabled');
            $('input[name=selectMessageForUpdate]').addClass('someClass');
        }
        else
        {
            $('input[name="updateMessage"]').removeAttr('disabled');
            $('input[name=selectMessageForUpdate]').removeClass('someClass');
        }
    });

});
$(函数(){
$('input[name=updateMessage]')。attr('disabled','disabled');
$('input[name=selectMessageForUpdate]')。键入(函数(){
if($('input[name=selectMessageForUpdate]').val().length<3)
{
$('input[name=updateMessage]')。attr('disabled','disabled');
$('input[name=selectMessageForUpdate]')。addClass('someClass');
}
其他的
{
$('input[name=“updateMessage”]”)。removeAttr('disabled');
$('input[name=selectMessageForUpdate]')。removeClass('someClass');
}
});
});
添加到css中:

textarea[name=selectMessageForUpdate].disabled { border:5px solid red }
input.indicated_textfield { border: 2px solid red; }
将addClass和removeClass行添加到Javascript代码中:

$(function() {

    $('input[name="updateMessage"]').prop('disabled', true);
    $('input[name="selectMessageForUpdate"]').keyup(function(){
        if($('input[name="selectMessageForUpdate"]').val().length < 3)
        {
            $('input[name="updateMessage"]').prop('disabled', true);
            $('input[name="selectMessageForUpdate"]').addClass('indicated_textfield');
        }
        else
        {
            $('input[name="updateMessage"]').prop('disabled', false);
            $('input[name="selectMessageForUpdate"]').removeClass('indicated_textfield');
        }
    });

});
$(函数(){
$('input[name=“updateMessage”]”)。prop('disabled',true);
$('input[name=“selectMessageForUpdate”]”)。键控(函数(){
if($('input[name=“selectMessageForUpdate”]').val().length<3)
{
$('input[name=“updateMessage”]”)。prop('disabled',true);
$('input[name=“selectMessageForUpdate”]”)。addClass('indicated_textfield');
}
其他的
{
$('input[name=“updateMessage”]”)。prop('disabled',false);
$('input[name=“selectMessageForUpdate”]”)。removeClass('indicated_textfield');
}
});
});

啊,是的,这适用于then按钮,但我想概述
文本字段
,当字符为
<3
@andreases时,它在该链接上工作,它动态工作,但在我的程序上,我必须单击其他位置以获得要显示的大纲:/anyideas@并编辑我的答案,并链接到jsfiddle,这就是你想要达到的目标吗?让我们等一下。。您使用的是输入还是文本区域?我正在使用jquery-1.7.2.js@elaxjin jquery 1.6.1+您应该使用prop方法,而不是attr/removeAttr。prop方法是1.6.1中的新方法,用于在加载页面后更改属性。我相应地更新了我的代码:)谢谢,禁用的代码仍然有效,但是
文本字段
的大纲不起作用:/我检查了
CSS
是否已加载,但它仍然没有显示在
文本字段
@elaxsjI意外地交换了更新消息,并在代码中选择了messageforupdate。请立即尝试。仍然没有列出文本字段:/