我正在尝试使用JavaScript函数focus()
,但在Safari浏览器上不起作用。我该如何解决这个问题?
<html lang="en">
<head>
<meta charset="UTF-8">
<title>demo</title>
<script type="text/javascript">
window.onload=function() {
document.getElementById('username').focus();
}
</script>
</head>
<body>
<input type="text" id="username" >
<input type="text" >
</body>
</html>
最佳答案
出于安全原因,iOS不允许自动触发.focus()
。