问题描述
我正在尝试添加显示“启用快照:[]”的复选框。如果用户单击该复选框,我想检查该复选框是否已选中。但是我遇到了类似的错误:document.getElementById(...)为空。
下面是代码:
instance.setHeaderItems(header => {
header.getHeader('toolbarGroup-Annotate').unshift({
type: 'customElement',render: function() {
const checkBox = document.createElement('input');
checkBox.type = 'checkBox';
checkBox.name = 'snap-to-grid';
checkBox.value = '1';
checkBox.id = 'snap-to-grid';
checkBox.onclick = function(evt) {
alert(document.getElementById('snap-to-grid').checked);
};
return checkBox;
}
});
});
那么有没有办法知道复选框是否被选中?另外,如何在复选框前添加一些文本?
解决方法
WebViewer在页面的iframe中运行。当我们渲染这些自定义按钮时,它们也位于该iframe中。要访问您的案例的元素,您首先需要获取iframe的文档。这应该对您有用
easy_install