javascript - 将 JavaScript 事件添加到 HTML 输入

标签 javascript html

此代码无法在 Firefox 中运行,但可以在 IE 和 Chrome 中运行。当我在文本框内单击时,它会运行 focusOut()focusIn() 函数。这种行为是预期的吗?语法是推荐的吗?

<!doctype html>

<html>
  <head>
    <title>Page of Cage</title>
    <meta charset="UTF-8">
    <link rel="icon" href="mkx-logo.png" type="image/x-icon">
    <script type="text/javascript">
      function focusIn() {
        alert("focus In!");
      };

      function focusOut() {
        alert("focus OUT!");
      };
    </script>	
  </head>
  <body>
    <form>	
      Name:<input onfocus="focusIn()" onblur ="focusOut()" type="text" name="name"/> <br/>
      <input type="submit" value ="submit"/>			
    </form>
  </body>
</html>	

最佳答案

alert 替换为 console.log 并使用开发人员工具观察您的网络浏览器控制台。正如nnnnnn在评论中所说。

关于javascript - 将 JavaScript 事件添加到 HTML 输入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31353070/

相关文章:

javascript - 如何在异步函数完成 Node js中的工作后调用函数

javascript - jQuery 脚本只执行一次

javascript - Selenium : scraping a page till all the products loaded

javascript - 取消方法内默认的onbefoarunload弹窗消息

javascript - Ember.js:内部引导过程中的 "Undefined is not a function"

javascript - 在 javascript 中检查内容 css

javascript - NodeJS - 如何使 res.render() 在函数之后运行而不是异步运行

html - Z-index 适用于 Firefox 和 IE,但不适用于 Chrome

html - 使省略号在 LI 中工作

html - 使用 Angular2 的 HTML 标签中的变量