[英]How to get the form element of the cursor in different forums or blogs to execute submit()?
我想使用JavaScript獲取不同論壇或博客中cursor的表單元素執行submit(),然后提交類型為“submit”的Input或Textarea,無需點擊提交按鈕或按Enter或Ctrl+Enter。
我無法在輸入或文本區域中獲取 cursor 的表單元素。
我試試這個,它只適用於某些論壇,在頂部執行搜索,但在 cursor 所在的位置回復,我不能在每個論壇或博客中設置不同的表格編號。 它在文本區域中不起作用,當按 Ctrl+Enter 時無法提交。
document.forms[0].submit()
我嘗試了這些,它們仍然不起作用。
this.submit()
this.form.submit()
完成了。
function getParentFormByChild(ele){
while(ele.parentNode.tagName.toLowerCase() !== 'body' && ele.parentNode.tagName.toLowerCase() !== 'form'){
ele = ele.parentNode
}
if(ele.parentNode.tagName.toLowerCase() === 'body' ) return null
return ele.parentNode
}
function 油猴子點擊圖標事件(){
let ele = "油猴子獲取當前光標所在input的dom元素"
let fromEle = getParentFormByChild(ele)
if(fromEle) fromEle.submit()
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.