小编kum*_*dya的帖子

在javascript中按tab键时如何调用函数?

我有一个这样的功能:

function whenEmpty(field) {
  if (field.value == '') {
     field.style.backgroundColor = "#ffcccc";
     alert("Please fill the field.");
     field.focus();
  } else {
     field.style.backgroundColor = "#ffff80";
  }
}
Run Code Online (Sandbox Code Playgroud)

在我考虑这个想法之前(我想在按下 tab 键时调用这个函数。)我在属性 onblur 上调用这个函数。

<tr>
  <td>
    <div class="required">
      <label>Phone</label>
    </div>
  </td>
  <td>
    <form:input path="connote.destPhone" id="destPhone" htmlEscape="true" onfocus="this.select();" onmouseup="return false;" onblur="whenEmpty(this);" style="background-color:#ffff80" size="20" maxlength="50" tabindex="9" />
    <form:errors path="connote.destPhone" cssClass="error" />
  </td>
</tr>
Run Code Online (Sandbox Code Playgroud)

但是现在我只想在按 Tab 键时调用该函数。

javascript enter onblur

3
推荐指数
1
解决办法
9001
查看次数

标签 统计

enter ×1

javascript ×1

onblur ×1