【问题标题】:Javascript focus on a textarea after ajax call back functionajax回调函数后,Javascript专注于文本区域
【发布时间】:2019-09-03 13:58:27
【问题描述】:

在使用 javascript 的 ajax 回调函数之后尝试专注于文本区域。这适用于 chrome 和 ie,但不适用于 IOS safari。直到这个场景,fucus 在我的 IOS 手机上运行良好。

这是我的想法,但没有成功。 textarea 出现,但出现后不聚焦(仅适用于我的 IOS 手机)。

if (window.XMLHttpRequest) { 
    xmlhttp = new XMLHttpRequest(); 
} else { 
    xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}

xmlhttp.onreadystatechange=function() { 
    if (this.readyState==4 && this.status==200) {
        document.getElementById('test_project').innerHTML=this.responseText;                     
        document.getElementById('textarea_1').focus();
    }
}   

xmlhttp.open("POST","../ajax/forms.php",true);      
xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); 
xmlhttp.send("phase=test");

这里是来自 ajax/forms.php 的示例代码

<textarea id='textarea_1' maxlength='23'></textarea>

推荐的链接似乎没有解决我的问题,但显示 IOS 确实存在焦点问题。任何其他建议表示赞赏。

【问题讨论】:

标签: javascript ajax forms focus


【解决方案1】:

这可以正常工作,没有问题。 你说它不关注IOS。试试这个: https://www.whatismybrowser.com/guides/how-to-enable-javascript/safari-iphone

【讨论】:

  • 感谢您的回复。我在手机上启用了 javascript。它在IOS上对你有用吗? Focus 在我的 IOS 手机上运行良好,但在这个场景中却没有。
  • 是的,很好!
猜你喜欢
  • 2011-12-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-06-26
  • 1970-01-01
  • 2011-12-27
  • 1970-01-01
  • 2011-10-11
相关资源
最近更新 更多