如何使用jquery使文本框只读

如何使用jquery使文本框只读,jquery,asp.net-mvc,knockout.js,Jquery,Asp.net Mvc,Knockout.js,我正在使用knockout和jquery的组合,我想知道如何在knockout或jquery中使文本框成为只读的('id/class')。attr('readonly',true); 您好,您还没有向我们展示您迄今为止的尝试,但是,我列出了一个可能对您有用的击倒和jquery示例。您还可以查看此链接以获得进一步的说明 <!-- ko if: if your condition is met --> <input type="text" class="input-xlarg

我正在使用knockout和jquery的组合,我想知道如何在knockout或jquery中使文本框成为只读的('id/class')。attr('readonly',true);
您好,您还没有向我们展示您迄今为止的尝试,但是,我列出了一个可能对您有用的击倒和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 -->

$(yourTextBox.prop('readonly',true)@StephenMuecke请不要将答案作为评论发布。她很可能知道它将作为一个副本关闭,并试图在不妨碍垃圾收集器的情况下帮助OP
// 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');