提高不同的事件,如果一个文本框的重点是与否 [英] Raise different events if a textbox is focused or not

查看:116
本文介绍了提高不同的事件,如果一个文本框的重点是与否的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在此网页上:

它是如何工作:为code中的Consultar按钮,搜索在Código文本框,并重新加载页面。在Salvar按钮调用一个例程,以节省你在该项目已经改变了。

How it works: the "Consultar" button searches for the code in the "Código" textbox and reloads the page. The "Salvar" button calls a routine to save what you have changed in that item.

这是我必须做的:如果Código文本框的重点,用户preSS回车,Consultar按钮的情况下,必须提高。如果Código文本框不集中,用户preSS回车,Salvar按钮的情况下,必须提高。

Here's what I gotta do: if the "Código" textbox is focused and the user press Enter, the event of the "Consultar" button must be raised. If the "Código" textbox is not focused and the user press Enter, the event of the "Salvar" button must be raised.

我不知道如何做到这一点,我试图做到这一点存在使用它按钮,但它不会工作,因为我需要一个不同的按钮是缺省的,如果文本框集中或不依赖。
我不知道,我可能会不得不使用一些javascript,但我不知道如何做到这一点的线索。

I don't know how to do this, I tried to do this using SetDefault button but it won't work cause I need a different button to be default depending if the textbox is focused or not. I wonder I that I'll probably have to use some javascript, but I have no clue about how to do it.

谁能帮我?

感谢您。

推荐答案

绑定的事件处理程序在你的文件的关键preSS事件,然后检查是否输入字段的重点。如果是这样,你可以提交搜索表单,否则,你继续你节省逻辑。

Bind an event handler to the keypress event on your document and then check if the input field is focused. If so, you can submit your search form, otherwise you continue with your saving logic.

看到这个小提琴看到它在行动: http://jsfiddle.net/KkJ2t/

See this fiddle to see it in action: http://jsfiddle.net/KkJ2t/

这篇关于提高不同的事件,如果一个文本框的重点是与否的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆