<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>test</title>
</head>
<script type="text/javascript">
<!--
var $ = function (id) {
return "string" == typeof id ? document.getElementById(id) : id;
};function checkValue(obj, v1, v2){
if(obj.value == '' || obj.value < v1 || obj.value > v2)
{
alert("Value range: " + v1 + "~" + v2);
obj.focus();
return false;
}
}-->
</script>
<body>
<form action="" method="get" name="form1">
<input name="rtp" type="text" value="" onBlur="javascript:checkValue(this, 0, 100);"/>
<input type="button" name="check" value="check" onclick="javascript:checkValue(this.form.rtp, 0, 100);"/>
</form>
</body>
</html>不知道为什么,在IE下rtp的onBlur和check的onclick执行checkValue函数时,"obj.focus();"有用,
但是在FF下,rtp的onBlur事件执行checkValue函数时,"obj.focus();"没有效果,
而在FF下,check的onclick执行checkValue函数时,"obj.focus();"有效果.
貌似是obj自己不能把焦点移到自己身上,谁教教我怎么改代码?
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>test</title>
</head>
<script type="text/javascript">
<!--
var $ = function (id) {
return "string" == typeof id ? document.getElementById(id) : id;
};function checkValue(obj, v1, v2){
if(obj.value == '' || obj.value < v1 || obj.value > v2)
{
alert("Value range: " + v1 + "~" + v2);
obj.focus();
return false;
}
}-->
</script>
<body>
<form action="" method="get" name="form1">
<input name="rtp" type="text" value="" onBlur="javascript:checkValue(this, 0, 100);"/>
<input type="button" name="check" value="check" onclick="javascript:checkValue(this.form.rtp, 0, 100);"/>
</form>
</body>
</html>不知道为什么,在IE下rtp的onBlur和check的onclick执行checkValue函数时,"obj.focus();"有用,
但是在FF下,rtp的onBlur事件执行checkValue函数时,"obj.focus();"没有效果,
而在FF下,check的onclick执行checkValue函数时,"obj.focus();"有效果.
貌似是obj自己不能把焦点移到自己身上,谁教教我怎么改代码?
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>test</title>
</head>
<script type="text/javascript">
<!--
var $ = function (id) {
return "string" == typeof id ? document.getElementById(id) : id;
};function checkValue(obj, v1, v2){
if(obj.value == '' || obj.value < v1 || obj.value > v2)
{
alert("Value range: " + v1 + "~" + v2);
//obj.focus();
obj.select();
return false;
}
}-->
</script>
<body>
<form action="" method="get" name="form1">
<input name="rtp" type="text" value="" onBlur="javascript:checkValue(this, 0, 100);"/>
<input type="button" name="check" value="check" onclick="javascript:checkValue(this.form.rtp, 0, 100);"/>
</form>
</body>
</html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>test </title>
</head>
<script type="text/javascript">
<!--
var $ = function (id) {
return "string" == typeof id ? document.getElementById(id) : id;
}; function checkValue(obj, v1, v2){
if(obj.value == '' || obj.value < v1 || obj.value > v2)
{
alert("Value range: " + v1 + "~" + v2);
window.setTimeout( function(){ obj.focus(); }, 0);
return false;
}
} -->
</script>
<body>
<form action="" method="get" name="form1">
<input name="rtp" type="text" value="" onBlur="javascript:checkValue(this, 0, 100);"/>
<input type="button" name="check" value="check" onclick="javascript:checkValue(this.form.rtp, 0, 100);"/>
</form>
</body>
</html>
改个方式就行了.
function checkValue(obj, v1, v2){
if(obj.value == '' || obj.value < v1 || obj.value > v2)
{
alert("Value range: " + v1 + "~" + v2);
//obj.focus();
window.setTimeout(obj.focus(), 0);
return false;
}
}结果我刚又试了下,这样改就没问题了:
function checkValue(obj, v1, v2){
if(obj.value == '' || obj.value < v1 || obj.value > v2)
{
alert("Value range: " + v1 + "~" + v2);
//obj.focus();
window.setTimeout(function(){ obj.focus(); }, 0);
return false;
}
}不明白为什么function里还可以加function? 谁可以给我解释解释?
document.insertForm.bsummary.focus();
return false;
public ActionForward fgfgfg(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {