<legend id='AViNR'><style id='AViNR'><dir id='AViNR'><q id='AViNR'></q></dir></style></legend>
    <i id='AViNR'><tr id='AViNR'><dt id='AViNR'><q id='AViNR'><span id='AViNR'><b id='AViNR'><form id='AViNR'><ins id='AViNR'></ins><ul id='AViNR'></ul><sub id='AViNR'></sub></form><legend id='AViNR'></legend><bdo id='AViNR'><pre id='AViNR'><center id='AViNR'></center></pre></bdo></b><th id='AViNR'></th></span></q></dt></tr></i><div id='AViNR'><tfoot id='AViNR'></tfoot><dl id='AViNR'><fieldset id='AViNR'></fieldset></dl></div>

    <small id='AViNR'></small><noframes id='AViNR'>

        <tfoot id='AViNR'></tfoot>
        • <bdo id='AViNR'></bdo><ul id='AViNR'></ul>

        焦点触发的模糊事件

        时间:2023-09-04
            1. <legend id='nCXLS'><style id='nCXLS'><dir id='nCXLS'><q id='nCXLS'></q></dir></style></legend>
              <tfoot id='nCXLS'></tfoot>

                <bdo id='nCXLS'></bdo><ul id='nCXLS'></ul>

                  <i id='nCXLS'><tr id='nCXLS'><dt id='nCXLS'><q id='nCXLS'><span id='nCXLS'><b id='nCXLS'><form id='nCXLS'><ins id='nCXLS'></ins><ul id='nCXLS'></ul><sub id='nCXLS'></sub></form><legend id='nCXLS'></legend><bdo id='nCXLS'><pre id='nCXLS'><center id='nCXLS'></center></pre></bdo></b><th id='nCXLS'></th></span></q></dt></tr></i><div id='nCXLS'><tfoot id='nCXLS'></tfoot><dl id='nCXLS'><fieldset id='nCXLS'></fieldset></dl></div>

                    <tbody id='nCXLS'></tbody>

                  <small id='nCXLS'></small><noframes id='nCXLS'>

                  本文介绍了焦点触发的模糊事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我正在使用以下代码jsFiddle:

                  function Field(args) {
                      this.id = args.id;
                  
                      this.name = args.name ? args.name : null;
                      this.reqType = args.reqType ? args.reqType : null;
                      this.reqUrl = args.reqUrl ? args.reqUrl : null;
                      this.required = args.required ? true : false;
                      this.error = args.error ? args.error : null;
                  
                      this.elem = document.getElementById(this.id);
                      this.value = this.elem.value;
                  
                      this.elem.addEventListener('blur', this, false);
                      this.elem.addEventListener('focus', this, false);
                  }
                  
                  // FormTitle is the specific field like a text field. There could be many of them.
                  function FormTitle(args) {
                      Field.call(this, args);
                  }
                  
                  Field.prototype.getValue = function() { return Helpers.trim( this.value ) };
                  
                  Field.prototype.blur = function (value) {
                      alert("blur");  
                  };
                  
                  Field.prototype.focus = function (value) {
                      alert("focus");  
                  };
                  
                  Field.prototype.handleEvent = function(event) {
                      var prop = event.type;
                      if ((prop in this) && typeof this[prop] == "function")
                          this[prop](this.value);
                  };
                  
                  inheritPrototype(FormTitle, Field);
                  var title = new FormTitle({name: "sa", id: "title"});
                  
                  function inheritPrototype(e, t) {
                      var n = Object.create(t.prototype);
                      n.constructor = e;
                      e.prototype = n
                  }
                  
                  if (!Object.create) {
                      Object.create = function (e) {
                          function t() {}
                          if (arguments.length > 1) {
                              throw new Error("Object.create implementation only accepts the first parameter.")
                          }
                          t.prototype = e;
                          return new t
                     }
                  }
                  

                  问题是每次使该字段成为焦点时都会触发模糊"事件,这与您的预期相反.尽管代码中甚至没有提到焦点事件,但这是事实.问题是我无法在 jsFiddle 中复制此问题,但问题发生在 IE 中.

                  The problem is that the 'blur' event is fired every time the field is brought to focus, which is opposite of what you'd expect. This is despite the fact that the focus event isn't even mentioned in the code. The problem is that I cannot replicate this problem in jsFiddle but the problem is happening in IE.

                  另外,在 jsFiddle 上,还有一个问题.多次触发焦点事件...

                  Also, on jsFiddle, there is another problem. The focus event is triggered multiple times...

                  对此有可能的解释和/或解决方案吗?

                  Is there a possible explanation for this and/or a solution?

                  奖金问题(最后是这个,承诺).我添加了一个函数 addEvent 来动态地将事件添加到表单字段,而不是直接在父构造函数中添加它们.这就是它的 jsFiddle.我正在尝试调用该函数,但它似乎不起作用.我可能做错了什么?

                  Bonus question (and last on this, promise). I added a function addEvent to dynamically add events to form fields instead of adding them all directly in the parent constructor. This is the jsFiddle for it. I am trying to call the function but it doesn't seem to work. What might I be doing wrong?

                  推荐答案

                  您的 focus 处理程序中的 alert 在获得焦点后立即将焦点从字段中移除.失去焦点会触发 blur.奇怪的是 blur 先出现.

                  The alert in your focus handler immediately removes focus away from the field as soon as it gains focus. The loss of focus triggers the blur. It is odd that the blur comes first.

                  如果您将警报更改为 console.log(或不会窃取焦点的内容),您将看到事件正确触发.

                  If you change the alerts to console.log (or something that does not steal focus), you will see that the events fire correctly.

                  http://jsfiddle.net/rsKQq/4/

                  这篇关于焦点触发的模糊事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:JavaScript 中的保留函数名 下一篇:覆盖“this"变量问题或如何调用成员函数?

                  相关文章

                  最新文章

                      <legend id='1UWUn'><style id='1UWUn'><dir id='1UWUn'><q id='1UWUn'></q></dir></style></legend>
                    1. <tfoot id='1UWUn'></tfoot>

                      <small id='1UWUn'></small><noframes id='1UWUn'>

                      <i id='1UWUn'><tr id='1UWUn'><dt id='1UWUn'><q id='1UWUn'><span id='1UWUn'><b id='1UWUn'><form id='1UWUn'><ins id='1UWUn'></ins><ul id='1UWUn'></ul><sub id='1UWUn'></sub></form><legend id='1UWUn'></legend><bdo id='1UWUn'><pre id='1UWUn'><center id='1UWUn'></center></pre></bdo></b><th id='1UWUn'></th></span></q></dt></tr></i><div id='1UWUn'><tfoot id='1UWUn'></tfoot><dl id='1UWUn'><fieldset id='1UWUn'></fieldset></dl></div>

                        <bdo id='1UWUn'></bdo><ul id='1UWUn'></ul>