[英]How can I add an oninput attribute to an element through HTML DOM?
[英]Add event to a html tag element through DOM
我有這個代碼
<input type="text" title="Search" tabindex="0" name="" aria-label="search input" role="searchbox" id="er_search_input_dummy" placeholder="Find your eBook" autocomplete="off">
並且我想在此iput標簽上添加onclick="this.select()"
,但不能直接對其進行編輯。 是否有通過DOM的方法或將其添加到<input>
像這樣
window.addEventListener("load", (e) => document.getElementById("er_search_input_dummy") .addEventListener("click",(e) => e.target.select()))
<input type="text" title="Search" tabindex="0" name="" aria-label="search input" role="searchbox" id="er_search_input_dummy" placeholder="Find your eBook" autocomplete="off">
如果需要this.select(),則需要function() {}
而不是(e) =>
:
window.addEventListener("load", (e) => document.getElementById("er_search_input_dummy") .addEventListener("click",function() { this.select(); }))
<input type="text" title="Search" tabindex="0" name="" aria-label="search input" role="searchbox" id="er_search_input_dummy" placeholder="Find your eBook" autocomplete="off">
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.