在哪个TextBox是光标。? [英] In Which TextBox is the cursor.?

查看:122
本文介绍了在哪个TextBox是光标。?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的网页中有4个文本框和一个提交按钮
假设用户在2个字段中输入数据,然后单击提交按钮。
我现在想知道在点击提交按钮之前光标位于哪个文本框中。

I have 4 textboxes and a submit button in my webpage Suppose the user enters data in 2 fields and then clicks the submit button. I now want to know in which textbox the cursor was located just before the submit button was clicked.

关于如何在javascript中执行此操作的任何想法.. ??

Any Idea on how to do this in javascript..??

推荐答案

你的问题确实在javascript中专门说 ,但是FWIW这里是jQuery中的另一个选项:

Your question does specifically say in javascript, but FWIW here is another option in jQuery:

在这里工作jsFiddle

HTML:

<input id="in1" type="text" /><br />
<input id="in2" type="text" /><br />
<input id="in3" type="text" /><br />
<input id="in4" type="text" /><br />
<input type="button" id="mybutt" value="Submit" />

jQuery:

var inFocus = false;

$('input, textarea').focus(function() {
  inFocus = $(this).attr('id');
});

$('#mybutt').click(function() {
    alert('Cursor was last in element id: ' + inFocus);
});

这篇关于在哪个TextBox是光标。?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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