[英]Input doesn't focus in Opera 54.0
我有一個輸入,試圖將焦點放在click事件上,該問題似乎僅在Opera中出現,並且我認為是因為在調用焦點之前有警報。
我的代碼在這里(在這個小提琴中 ):
function Validate(){ var element=document.getElementById('test-input'); if(element.value=="") { alert("Please complete the field!"); element.focus(); } }
<input id="test-input"/> <input type="button" value="Click" onClick="Validate();"/>
它實際上可以在Opera 55.0中使用,但不會使光標閃爍。 如果您在消息后立即開始鍵入內容,它將以具有焦點的字段開頭。 您可以為該字段添加一些樣式,其周圍的紅色邊框或其他視覺效果,以適應這種情況。
-更新-
在完成對話以提高Opera對焦點的意識之后,像在那已經消失的小提琴中所做的那樣,在野外工作很可能:
像這樣:
function Validate(){
var element=document.getElementById('test-input');
if(element.value=="")
{
window.alert("Please complete the field!");
element.style.border = "solid 1px red";
element.focus();
} else {
element.style.border = "";
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.