Created
August 19, 2024 15:35
-
-
Save jerrylususu/07b44fb6b8c9cd298bb9eb69d26820fa to your computer and use it in GitHub Desktop.
hack element-ui DateTimePicker
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
javascript:(function() { | |
// 获取当前时间 | |
var now = new Date(); | |
var formattedTime = now.toISOString().slice(0, 16); // 格式化为 YYYY-MM-DDTHH:MM | |
// 找到 DateTimePicker 的 input 元素 | |
var inputElement = document.querySelector('.el-date-editor input'); | |
if (inputElement) { | |
// 模拟用户点击 input 元素 | |
inputElement.click(); | |
// 设置 input 的 value 属性 | |
inputElement.value = formattedTime; | |
// 创建并分发 input 事件 | |
var inputEvent = new Event('input', { bubbles: true }); | |
inputElement.dispatchEvent(inputEvent); | |
// 创建并分发 change 事件 | |
var changeEvent = new Event('change', { bubbles: true }); | |
inputElement.dispatchEvent(changeEvent); | |
// 模拟用户失去焦点 | |
inputElement.blur(); | |
} else { | |
console.error('DateTimePicker input element not found'); | |
} | |
})(); |
input.dispatchEvent(new Event("focus", {bubbles: true})
input.dispatchEvent(new KeyboardEvent("keydown", {key: 'Esc', keyCode: 27, bubbles: true})
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
may also need
focus
event