首页 > 解决方案 > 如何使用 GreaseMonkey/TamperMonkey 更改文本字段的输入属性?

问题描述

如何从此输入字段中删除只读属性?

<input class=" calendar_field" id="zoom_meeting_room[scheduled_on]" name="zoom_meeting_room[scheduled_on]" readonly="readonly" type="text" value="2020-11-07 12:08">

谢谢

标签: google-chromegreasemonkeytampermonkey

解决方案


这是一个例子:

document.querySelector('#zoom_meeting_room[scheduled_on]').removeAttribute('readonly');

或者

document.getElementById('zoom_meeting_room[scheduled_on]').removeAttribute('readonly');

为了避免错误

const input = document.getElementById('zoom_meeting_room[scheduled_on]');
if (input) { input.removeAttribute('readonly'); }

或者

const input = document.getElementById('zoom_meeting_room[scheduled_on]');
input && input.removeAttribute('readonly');

您也可以将其设置为false

const input = document.getElementById('zoom_meeting_room[scheduled_on]');
if (input) { input.readOnly = false; }

或者

const input = document.getElementById('zoom_meeting_room[scheduled_on]');
if (input) { input.setAttribute('readonly', false); }

推荐阅读