jquery - 页面加载时如何锁定/只读 Bootstrap 标签输入字段?

标签 jquery twitter-bootstrap tags bootstrap-tags-input

我正在使用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/

相关文章:

css - 如何覆盖为所有选择器设置的 css 设置

html - 将所有 Bootstrap 内容放入可视区域

html - 如何在 Bootstrap 中更改整个 html 文档的字体粗细?

html - 如何防止 CKEditor 剥离 < 和 >(大于/小于)

javascript - 使用 jquery 插件 slick carousel 自定义箭头和点

Jquery .click() 更胜一筹

javascript - jQuery 自动完成插件在 ajax 加载的内容中不起作用

javascript - 访问函数内部调用事件的 JQuery 对象

mysql - 计算文本字段(用户帖子)中的#tags

html - 如何在 html Action 链接中包含 i 标签?