大佬教程收集整理的这篇文章主要介绍了javascript focus()不专注,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我的HTML:
<form name="basicText" id="basicText" action=""> <p>Enter any ol' Integer: <input type="text" id="inputBox" name="inputBox" size="14"/> <input value = "Next...?" type="submit" id="mySubmitBtn" name="mySubmitBtn"/> </p> </form> <script src="js/w1bscript.js" type="text/javascript"></script>
另请注意,外部javascript文件在末尾添加,因此所有元素都可以加载(现在不用担心onload).
JavaScript:
var myButton1 = document.getElementById("mySubmitBtn"); var myForm1 = document.getElementById("basicText"); var myTextBox = myForm1.inputBox; function submitPress() { if(myTextBox.value.length == 0) { alert("You didn't enter anything! Once more time,with feeling...") basicText.focus(); basicText.SELEct(); } else if(/\s/.test(myTextBox.value)) { alert("Eh... No spaces. Just Integers. Try again..."); basicText.focus(); basicText.SELEct(); } else if (isNaN(myTextBox.value)==truE) { alert("Eh... Gonna need you to enter ONLY digits this time. kthnx."); basicText.focus(); basicText.SELEct(); } else { // The textbox isn't empty,and there's no spaces. Good. alert("you've passed the test!") } } myButton1.addEventListener('click',submitPress,falsE);
当我输入错误的输入时,逻辑工作,但无论我使用什么浏览器,光标都不会聚焦回文本框.
小提琴:http://jsfiddle.net/2CNeG/
谢谢,
唐
以上是大佬教程为你收集整理的javascript focus()不专注全部内容,希望文章能够帮你解决javascript focus()不专注所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。