我想更改一些dom内容,以便在用户可以看到之前,所有输入字段值都是网页的""
。我该怎么做?有没有办法做到这一点?
感谢。
答案 0 :(得分:2)
您需要一个在document_start上运行的内容脚本,以及两种方法之一:
添加CSS样式覆盖以使INPUT文本透明,并在加载页面时清除元素并删除样式:
的manifest.json:
"content_scripts": [{
"matches": ["<all_urls>"],
"run_at": "document_start",
"all_frames": true,
"js": ["content.js"]
}],
content.js:
// document is empty now so we'll only add the style
var style = document.documentElement.appendChild(document.createElement('style'));
style.textContent = 'input {color: transparent !important;}';
// once DOM is ready clear the inputs
document.addEventListener('DOMContentLoaded', function() {
var inputs = document.getElementsByTagName('input');
for (var i = inputs.length; --i >= 0; ) {
var input = inputs[i];
if (input.value) {
input.value = '';
}
}
style.remove();
});