Skip to content

Instantly share code, notes, and snippets.

@imzhi
Created November 13, 2023 08:25
Show Gist options
  • Save imzhi/c07ec8a319e7df06c9cbcc3e13b7c804 to your computer and use it in GitHub Desktop.
Save imzhi/c07ec8a319e7df06c9cbcc3e13b7c804 to your computer and use it in GitHub Desktop.
vue 网页模拟输入并点击!
const event = document.createEvent('HTMLEvents')
event.initEvent('input', true, true)
event.eventType = 'message'
setInterval(() => {
const aainput = document.querySelector("#app > div > div.content > div.message-box > div.footer > input")
aainput.value = new Date().toGMTString()
aainput.dispatchEvent(event)
const btn = document.querySelector("#app > div > div.content > div.message-box > div.footer > button:nth-child(3)")
btn.click()
}, 10);
@imzhi
Copy link
Author

imzhi commented Nov 13, 2023

参考文章:vue和react使用js模拟键盘输入 https://blog.csdn.net/weixin_46774564/article/details/123254550

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment