[英]How to activate :focus on the input+button when a user click into the input?
[英]How to activate text input on a button click in javascript
我正在嘗試使用按鈕激活文本輸入。 我的功能是這樣的。
function showHide4()
{
document.getElementById('snack').readOnly=false;
document.getElementById('snack').style.backgroundColor"#ffffff";
}
此功能使文本輸入可寫並將背景更改為白色,但是只有在單擊它后才能激活。
注意:-我激活的文本輸入的想法是其中的光標(|)閃爍。 也許激活不是一個正確的詞,但我不知道該怎么稱呼它。
編輯:-我嘗試過focus(),使用focus()的問題是我的文本輸入中的默認值被自動選擇,這不是我想要的,我想在該值之后放置cursor(|)。
試試這個,我認為focus()
是您要尋找的:
function showHide4() {
var el = document.getElementById('snack');
el.readOnly = false;
el.style.backgroundColor = "#ffffff";
el.focus();
el.value = el.value;
};
要做您想做的事情,您需要作弊,只需重置(再次設置)輸入的值,它就可以根據需要工作。
function showHide4()
{
document.getElementById('snack').readOnly = false;
document.getElementById('snack').style.backgroundColor = "#ffffff";
document.getElementById('snack').focus();
}
這將起作用!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.