【问题标题】:Making textfield greyed out/disabled after saving data to database (ajax/php)将数据保存到数据库后使文本字段变灰/禁用(ajax/php)
【发布时间】:2015-04-06 15:59:56
【问题描述】:

我有以下代码:

<input type="text" value="name" id="name" />
<input type="button" id="button" value="Click Me" /></p>

<script>
    $( "#button" ).click(function() {
        var text = $("#name").val();
        $.ajax({
            url: 'page.php',
            type: "POST",
            data: {
                text: text
            },
            success: function(response) {
                alert("inserted");
            }
        });
    });
</script>

现在一切正常,但是单击按钮后,我收到弹出消息(警报),说数据已插入。而不是我想将文本字段变灰 - 有可能吗?

【问题讨论】:

  • 您是否尝试在成功回调的输入中添加disabled 属性?
  • 下次请尝试用谷歌搜索。 “jquery disable input”会给你同样的答案

标签: javascript php jquery ajax textfield


【解决方案1】:

您可以使用prop() 禁用文本输入。这也会在大多数浏览器中变灰。试试这个:

success: function(response) {
    $('#name').prop('disabled', true);
}

【讨论】:

    【解决方案2】:
    function disable(){
      $("#name").prop("disabled",true);
    }
    

    【讨论】:

      【解决方案3】:

      ajax成功回调后试试这个方法,

          $("#name").attr('readonly', 'true'); // mark it as read only
          $("#name").css('background-color' , '#DEDEDE'); // change the background color
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2013-06-03
        • 1970-01-01
        • 2015-10-04
        • 2014-09-22
        • 2014-02-14
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多