【问题标题】:Jquery - Disabling text field and re enabling fieldsJquery - 禁用文本字段并重新启用字段
【发布时间】:2013-05-01 03:18:17
【问题描述】:

是否有一个 jquery 函数来限制一个文本字段的一次提交,一旦它被提交?一旦用户删除了该字段中的现有信息,如果他们改变主意,提交按钮将重新启用,他们将能够重新提交他们的文本。

例如:

-用户正在制作一件 T 恤 -Tshirt 产品上只允许一行文字 - 一旦他们在字段中插入文本,该字段就会被禁用 -如果他们删除或重置文本字段,则可以重新启用字段。

提前致谢!

【问题讨论】:

  • 没有一个函数能做到这一点,没有。
  • @nullability theres no jquery way to make it after submit, it disable the field so they can't change it?
  • 如果您禁用文本字段,他们将无法返回并更新文本。您必须创建一个单独的控件,如按钮,以启用该按钮。 Example

标签: jquery input field


【解决方案1】:

我建议使用监听事件来限制输入的字符数,并在达到该限制后禁用该字段。然后可能是一个重置按钮重新开始。

例如:

//this function would freeze the field if they reach a char max.
//I would suggest changing the field color tho, and disabling the
//submit button if they exceed the max
$("#tshirt_text").keyup(function(){
    var content = $(this).val();
    if( content.length = 26 ) { //or whatever your char max is
        $(this).prop( "disabled", true );
    }
});

//this function could freeze the field when it loses focus 
$("#tshirt_text").blur(function(){
    $(this).prop( "disabled", true );
}

//clear the field onclick
$("#clearButton").click(function(){
    $("#thsirt_text").prop( "disabled", false );
}

【讨论】:

    猜你喜欢
    • 2014-01-06
    • 1970-01-01
    • 2012-10-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-10-11
    • 1970-01-01
    • 2013-07-24
    相关资源
    最近更新 更多