简体   繁体   English

在javascript代码中将文本的attr更改为“readonly false”

[英]change attr of text into "readonly false" inside of the javascript code

I have here a html code inside the javascript one and it will append that on my modal, my question is how can I set to readonly=false property in order textbox to be enabled.我在 javascript 中有一个 html 代码,它会将它附加到我的模态上,我的问题是如何设置为readonly=false属性以便启用文本框。 I'm trying jquery but it's not working.我正在尝试 jquery,但它不起作用。 The group of textboxes must be enabled when calling the class.调用类时必须启用文本框组。

<script>
  var html;
 for ( x=0 ; x < 5 ; x++)
  {
    html +=' <input type="text" class="changeintofalse" readonly/>';
  }

  $('#details_info').html(html);
  $('#itemsModal').modal('show');
</script>

How can I set to readonly=false property in order textbox to be enabled如何设置为readonly=false属性以便启用文本框

There is no readonly="false" setting.没有readonly="false"设置。 If the readonly attribute exists on the element, with any value, then the field will be readonly.如果元素上存在readonly属性,具有任何值,则该字段将是只读的。

If you want to make the element editable again you need to remove that attribute.如果您想让元素再次可编辑,您需要删除该属性。 Using jQuery the best practice would be to use prop() :使用 jQuery 的最佳实践是使用prop()

$('#foo').prop('readonly', false);

However using removeAttr() will work too:但是使用removeAttr()也可以:

$('#foo').removeAttr('readonly');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM