【问题标题】:How can I make a textbox readonly using jquery [duplicate]如何使用 jquery 将文本框设为只读 [重复]
【发布时间】:2018-07-30 14:46:10
【问题描述】:

我正在使用敲除和 jquery 的组合,我想知道如何在敲除或 jquery 中将文本框设为只读

【问题讨论】:

  • $(yourTextBox).prop('readonly', true);
  • @StephenMuecke 请不要将答案发布为 cmets
  • 他很可能知道它即将作为副本关闭,并试图在不妨碍垃圾收集器的情况下帮助 OP

标签: jquery asp.net-mvc knockout.js


【解决方案1】:
$('id/class').attr('readonly', true);

【讨论】:

    【解决方案2】:

    您好,到目前为止,您还没有向我们展示您尝试过的内容,但是,我列出了一个可能对您有用的淘汰赛和 jquery 示例。您还可以查看此链接以获得进一步说明。

    <!-- ko if: if your condition is met  -->
      <input type="text" class="input-xlarge" data-bind="value:  texboxValue" id="textboxID"  />
    <!-- /ko -->
    
    <!-- ko ifnot: if your condition is not met -->
      <input type="text" class="input-xlarge" data-bind="value:  texboxValue" id="textboxID" textboxName" readonly />
    <!-- /ko -->
    

    然后在 jQuery 方面:

    // this will make you textbox readonly
    $("#textboxID").attr('readonly', 'readonly');
    
    // this will remove the readonly attribute from your text box read/writeable
    $("#textbox").removeAttr('readonly');
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多