繁体   English   中英

在包含带有jQuery或js的html的变量中禁用更改属性

[英]change property disabled in a variable containing html with jquery or js

我需要禁用进入变量的类“ gcf_crud”的元素。

我的错误代码是:

var defText = ''+
'   <div class="form-group col-md-12">'+
'       <h4 id="minimum-setp">{{title}}</h4>'+
'       <input type="text" class="form-control gcf_crud" id="txtUsuari" value="{{data}}"/>'+
'   </div>';
var defTextDisabled = $(defText).find('.gcf_crud').prop('disabled', true);

使用此代码,我仅获得输入,但是我需要所有原始html。

我该怎么办?

问候,希克

您的defTextDisabled变量仅由于.find('.gcf_crud')而返回输入。

但是似乎您需要对包含所有元素的jQuery对象的引用(变量)。 为此,请按以下步骤分解流程:

 var defText = '<div class="form-group col-md-12">' + '<h4 id="minimum-setp">{{title}}</h4>' + '<input type="text" class="form-control gcf_crud" id="txtUsuari" value="{{data}}"/>' + '</div>', $defText = $(defText); // Save the entire thing here // Now, you can disable the input $defText.find('.gcf_crud').prop('disabled', true); // And use the whole content $('body').append($defText); 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.1/jquery.min.js"></script> 

gcf_crud类添加到主div中。

暂无
暂无

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

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