<html>
<head>
<script type="text/javascript">
function aa(){
if(document.getElementById('txt1').value == ''){
alert('please input some text');
}
}
</script>
</head>
<body>
<form>
<input id="txt1" type="text" value="" onblur="aa();" />
<input id="txt2" type="text" value="" />
<input id="txt3" type="text" value="" />
<input id="submit" type="submit" />
</form>
</body>
</html>如果txt1中为空时光标转移的话会触发onblur 此时alert了 那么在按下确定后让光标回到txt1呢
解决方案 »
- 一段js,通常情况下没什么问题,但在某个时候后台接值时会报userid未定义或输出+userid+,求解
- innerHTML 中 双引号 问题
- 高分请教firefox下的一个问题
- 现在学JAVASCRIPT好迷茫,不知道从何下手,哪位过来人给点建议?
- [高手快来]关于JavaScript中增删Checkbox组的一项或几项~~
- 怎样使本页所有的链接都自动加上?dns=1
- javascript调用本地应用程序的问题!奇难
- 在JS里面如何获得IMG的属性?
- !!!请问VBscript中类似continue的语句是什么?急!!!
- easyui datagrid 的小问题
- 将HTML中表格转换为EXCEL
- 函数属性定义为另一个函数 时的疑惑?
alert('please input some text');
document.getElementById('txt1').focus();
}
ie下可以,但是ff下就不行了
<html>
<head>
<script type="text/javascript">
function aa(obj){
if(obj.value == 'a'){
alert('please input some text');
obj.focus();
}
}
</script>
</head>
<body>
<form>
<input id="txt1" type="text" value="" onblur="aa(this);" />
<input id="txt2" type="text" value="" onblur="aa(this);" />
<input id="txt3" type="text" value="" onblur="aa(this);" />
<input id="submit" type="submit" />
</form> </body>
</html>改成通用点的了,但是在ff下还是不行,我的ff是3.5.2的 奇怪中
google到 都是要加上这句话,不过为什么还是没明白
JS水平太菜了 -_-!
document.getElementById('txt1').focus();
alert('please input some text');
} 换个顺序试试
你这个调用时候多了一个“;”吧。
刚才我在IE和ff下也试验过了,ff下用window.setTimeout(function(){ obj.focus(); }, 0);
这个也没用。
关闭页面的时候也要谈出alert的内容,切换窗口也要谈出来。
超级不爽,
ff下始终不成功。
不过alert不是友好的方式
最好用层来显示错误信息
document.getElementById('txt1').select();
<head>
<script type="text/javascript">
function aa(){
if(document.getElementById('txt1').value == ''){
alert('please input some text');
document.getElementById('txt1').focus();
document.getElementById('txt1').select();
}
}
</script>
</head>
<body>
<form>
<input id="txt1" type="text" value="" onblur="aa();" />
<input id="txt2" type="text" value="" />
<input id="txt3" type="text" value="" />
<input id="submit" type="submit" />
</form>
</body>
</html>
都用上试一试
多谢各位的帮助,可能结贴有点早了,呵呵,下次慢点结贴就是了 呵呵
alert('please input some text');
document.getElementById('txt1').focus();
}//focus();得到焦点
//onblur();失去焦点