如何通过使用TAB在光标上调用某个函数进入输入文本框?

时间:2017-02-24 17:11:12

标签: javascript jquery html

我只是想通过按TAB键将表格上的光标移动到输入文本框时调用一个函数。当我点击它时也是如此...&gt;我只想显示一条消息.h html代码 - &gt; < / p>

<input onclick="$('#limitDayExitWarning').show(),$('#limitDayExitWarning').html('Plase insert a value [1|2].Means, how many day of this batch class will be held in one Week')" class="w3-input w3-border w3-animate-input" type="number" placeholder="Day In A Week*" id="idayInAWeek" name="dayInAWeek" autocomplete="off">
  <label id="limitDayExitWarning" style="display: none;color: red;"></label>

单击时show / apper html上的级别 - &gt;表示当光标使用鼠标移动时。但是当我使用Tabs将光标从其他字段移动到我的欲望字段时,我的愿望级别没有显示。

我也试过OnFocus

<input onfocus="$('#limitDayExitWarning').show(),$('#limitDayExitWa‌​rning').html('Plase insert a value [1|2].Means, how many day of this batch class will be held in one Week')" onclick="$('#limitDayExitWarning').show(),$('#limitDayExitWa‌​rning').html('Plase insert a value [1|2].Means, how many day of this batch class will be held in one Week')"
class="w3-input w3-border w3-animate-input" type="number" placeholder="Day In A Week*" id="idayInAWeek" name="dayInAWeek" autocomplete="off">
<label id="limitDayExitWarning" style="display: none;color: red;"></label>

1 个答案:

答案 0 :(得分:0)

当用户标记,点击或以其他方式进入focus时,使用<input>事件执行某些操作。使用blur在他们离开时执行某些操作:

<input type="number" id="idayInAWeek" name="dayInAWeek">
<label id="limitDayExitWarning">blah blah</label>

<script>
    $(function(){
        $('#idayInAWeek').
            on('focus', function() { $('#limitDayExitWarning').show(); }).
            on('blur', function() { $('#limitDayExitWarning').hide(); });
    });
</script>