jquery 小问题

passself 2010-04-08 03:31:36

<!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=utf-8" />
<title>无标题文档</title>
<script src="jquery-1.3.2.js"></script>
<script>
$(document).ready(function(){
$("#test1").focus();
});
</script>
</head>

<body>
<form name="form1" id="test_form1">
<input type="text" name="test1" id="temp1" />
<input type="text" name="test2" id="temp2" />
</form>
<form name="form2" id="test_form2">
<input type="text" name="test3" id="temp3" />
<input type="text" name="test4" id="temp4" />
</form>
<select id="select">
<option>语言选择</option>
<option>CN</option>
<option>EN</option>
</select>
</body>
</html>


我想要的效果是:当这四个输入框输入文字的时候,我点击选择语言的下拉框之后,焦点还回到刚才正在输入文字的输入框中怎么办,谢谢大家,jquery或者js的代码都可以
...全文
102 13 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
shan1119 2010-04-08
  • 打赏
  • 举报
回复
[Quote=引用 11 楼 lieri111 的回复:]
以上代码在第二个第三个和第四个可以,在默认的第一个中是不行的
[/Quote]

<script>
var obj;
$(document).ready(function(){
obj=$("input:first");
$("input").focus(function(){
obj=this;
});
$("select").change(function(){
if(obj)obj.focus();
});
});
</script>
usersname 2010-04-08
  • 打赏
  • 举报
回复
次序要调整一下,先设置事件在活动焦点,这obj才有值

    $("input[type=text]").focus(function() {
obj = this;
});
$("#temp1").focus();
passself 2010-04-08
  • 打赏
  • 举报
回复
以上代码在第二个第三个和第四个可以,在默认的第一个中是不行的
usersname 2010-04-08
  • 打赏
  • 举报
回复
后面的效果挺难实现,没有想到什么好的方法判断下拉框是否关闭。
passself 2010-04-08
  • 打赏
  • 举报
回复
就没有焦点了
passself 2010-04-08
  • 打赏
  • 举报
回复
大家好,你们在ff下试了吗?在我这里为什么select改变之后就可以焦点了
shan1119 2010-04-08
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 vnetcbd 的回复:]
2楼的 学习了

有个问题

如果 select change不改变值

怎么办??就返回不了上一次input的焦点了
[/Quote]
$("select").change(function(){
if(obj)obj.focus();
});
$("select").blur(function(){
if(obj)obj.focus();
});
teerhu 2010-04-08
  • 打赏
  • 举报
回复
<html>
<head>
<script src="jquery-1.3.2.min.js"></script>
<script>
$(function(){
var cur;
$('input[type=text]').blur(function(){ cur=$(this);});

$("#select").change(function(){ if(cur) cur.focus(); });

});


</script>
<body>
<form name="form1" id="test_form1">
<input type="text" name="test1" id="temp1" />
<input type="text" name="test2" id="temp2" />
</form>
<form name="form2" id="test_form2">
<input type="text" name="test3" id="temp3" />
<input type="text" name="test4" id="temp4" />
</form>
<select id="select">
<option>语言选择</option>
<option>CN</option>
<option>EN</option>
</select>
</body>
</html>
usersname 2010-04-08
  • 打赏
  • 举报
回复
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=utf-8" />
<title>无标题文档</title>
<!--script src="jquery-1.3.2.js"></script-->
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js"></script>
<script>
$(document).ready(function(){
var obj;
$("#temp1").focus();
$("input[type=text]").focus(function() {
obj = this;
});
$("#select").change(function() {
obj.focus();
});
});
</script>
</head>

<body>
<form name="form1" id="test_form1">
<input type="text" name="test1" id="temp1" />
<input type="text" name="test2" id="temp2" />
</form>
<form name="form2" id="test_form2">
<input type="text" name="test3" id="temp3" />
<input type="text" name="test4" id="temp4" />
</form>
<select id="select">
<option>语言选择</option>
<option>CN</option>
<option>EN</option>
</select>
</body>
vnetcbd 2010-04-08
  • 打赏
  • 举报
回复
2楼的 学习了

有个问题

如果 select change不改变值

怎么办??就返回不了上一次input的焦点了
usersname 2010-04-08
  • 打赏
  • 举报
回复
明明是temp为何要写成test
<!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=utf-8" />
<title>无标题文档</title>
<!--script src="jquery-1.3.2.js"></script-->
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("#temp1").focus();
$("#select").change(function() {
$("#temp1").focus();
});
});
</script>
</head>

<body>
<form name="form1" id="test_form1">
<input type="text" name="test1" id="temp1" />
<input type="text" name="test2" id="temp2" />
</form>
<form name="form2" id="test_form2">
<input type="text" name="test3" id="temp3" />
<input type="text" name="test4" id="temp4" />
</form>
<select id="select">
<option>语言选择</option>
<option>CN</option>
<option>EN</option>
</select>
</body>
shan1119 2010-04-08
  • 打赏
  • 举报
回复

<!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=utf-8" />
<title>无h・文档</title>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script src="jquery-1.3.2.js"></script>
<script>
var obj;
$(document).ready(function(){
$("input").focus(function(){
obj=this;
});
$("select").change(function(){
if(obj)obj.focus();
});
});
</script>
</head>

<body>
<form name="form1" id="test_form1">
<input type="text" name="test1" id="temp1" />
<input type="text" name="test2" id="temp2" />
</form>
<form name="form2" id="test_form2">
<input type="text" name="test3" id="temp3" />
<input type="text" name="test4" id="temp4" />
</form>
<select id="select">
<option>寀言 宣b</option>
<option>CN</option>
<option>EN</option>
</select>
</body>
</html>
vnetcbd 2010-04-08
  • 打赏
  • 举报
回复
晕,太多焦点了,不好 返回上一次输入框的焦点
本次更新内容主要是BUG修复和功能改进,相隔4个月又发布了新版本,这次更新更像是例行公事,不过好在修复了很多BUG,另外需要说一下,EasyUI框架当中其实官方还隐藏了不少API没有开放出来,有些朋友建议我把整理一下,将一些好用的API及其用法也更新到中文API中,这里我想说的是,有些API或许是因为不稳定、尚有BUG、未完全实现或者是未经过完整测试的,所以官方并未公布出来,因此我也不建议大家大面积的去使用,这样会带来很多不稳定因素,甚至是致命的BUG,这也是我没有将这些API写入中文API文档的原因,所以有能力并且需要的人就自行去源代码中挖掘吧,我这里只同步官网的API(外加少许的变动或者不影响稳定性和安全性的新增内容)。 jQuery EasyUI 1.4.4版本更新内容: Bug(修复) filebox:修复“clear”和“reset”方法在IE9下无法正常工作的问题; messager:修复调用无参的$.messager.progress()方法之后,再调用$.messager.progress('close')方法时无法正常工作的问题; timespinner:修复在IE8中点击微调按钮时无法正确显示值的问题; window:修复在“onMove”事件中调用“options”方法时无法正常显示的问题; treegrid:修复“getLevel”方法无法接受为0的参数值的问题。 Improvement(改进) layout:改进后的“collapsedContent”、“expandMode”和“hideExpandTool”属性可以支持区域面板; layout:改进后的“hideCollapsedContent”属性可以在折叠面板上设置显示垂直标题栏; layout:新增“onCollapse”、“onExpand”、“onAdd”、“onRemove”事件; datagrid:在排序列的标题上显示↑↓图标; datagrid:新增“gotoPage”方法; propertygrid:新增“groups”方法,以允许获取所有数据租; messager:在显示长消息的的时候支持对消息进行自动滚动; tabs:“disabled”属性支持定义一个被禁用的选项卡面板; tabs:支持百分比大小。

87,992

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧