我正在使用bootstrap-tagsinput 。这正在正常工作。
但是,当页面加载时,我希望 bootstrap-tagsinput 字段为只读(即被锁定且无法输入文本)。
我编写了一些代码,允许在选中/取消选中 bool 复选框时锁定/解锁 bootstrap-tagsinput 字段。
该代码正在运行。这是:
<script type="text/javascript">
$(document).ready(function() {
// lock the tags input field.
$("#id_bootstrap_tagsinput_tag_input").attr('readonly', true);
// when the user changes the search engine ressults option, lock / unlock the tags input..
$('#id_resume_published_details_search_engine_results').change(function() {
if($(this).is(":checked")) {
// unlock the tags input field.
$("#id_bootstrap_tagsinput_tag_input").attr('readonly', false);
} else {
// remove all tags before locking the input field.
$('#id_bootstrap_tagsinput_tag_wrapper').tagsinput('removeAll');
// lock the tags input field.
$("#id_bootstrap_tagsinput_tag_input").attr('readonly', true);
}
});
});
</script>
但是,当页面最初加载时,bootstrap-tagsinput 字段并未锁定/只读。
有人可以建议为什么 bootstrap-tagsinput 字段在页面加载时不是只读/锁定的吗?
谢谢。
[编辑]
我尝试使用 $("#id_bootstrap_tagsinput_tag_input").attr('disabled', 'disabled');
但这没有效果。
最佳答案
这似乎总是最适合我:
$("#id_bootstrap_tagsinput_tag_input").prop('disabled', true);
当然,相反地重新启用:
$("#id_bootstrap_tagsinput_tag_input").prop('disabled', false);
关于jquery - 页面加载时如何锁定/只读 Bootstrap 标签输入字段?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54068523/