我没有'我不理解js的结构

I don't understand that js construction

本文关键字:js 结构 不理解      更新时间:2023-09-26

我有代码

 t.prototype.checkFields = function () {
      var e = this,
      t = this.$container.find('.form-fieldset'),
      a = 0;
      return t.filter(':visible').each(function (t, i) {
        var s = $(i),
        n = s.find('input[type="text"], input[type="password"], input[type="email"]'),
        r = n.data('write-id');
        - 1 === e.settings.emptyIgnoring.indexOf(r) && n.length && !n.prop('disabled') && (n.val().trim() || (a++, s.addClass('is-js-error').find('.form-fieldset__error').html('Заполните поле')))
      }),
      a
  },

如果输入为空,但我不知道条件是什么时候发生的,写下文本,我看不到if (...) then write text

为什么addClass与&?添加类时返回什么,对吗?

那是什么?

我很少读到关于原型的内容,在引导程序和jQuery源中可以看到

 - 1 === e.settings.emptyIgnoring.indexOf(r)  //indexOf return r position, and is -1 if not found for example one string in another 
 && n.length // that mean that length of n is bigger than 0
 && !n.prop('disabled') //is not set attribute disabled=true is equal i think with attr('disabled')==true
 && (n.val().trim() //removes newlines, spaces and other from the beginning and end of the n value
 || (a++, //increment but why is need here
 s.addClass('is-js-error') //add class name
 .find('.form-fieldset__error') // find child element with class form-fieldset__error
 .html('Заполните поле'))) // set the html to element with class form-fieldset__error

表单提交时发送的帖子请求是(电话和电子邮件为空,我还写了$('input').val('text');并且在发送表单和数据之后也是空的)

  token[3853526949671]:4dd0e6e302563d00
  source:add
  captcha:Maxim
  email:asdasd@mm.nn
  private:1
  phone:
  name:

我需要填充输入并传递验证函数,该函数返回输入为空的文本,但返回$('input[type=text]').val('some-text');并提交表单给我输入的文本没有用文本填充,我认为该功能显示标签和块表单执行后的

用一些注释美化了函数的版本
返回包含空文本、密码或电子邮件输入的可见表单字段集的数量
忽略禁用的输入和emptyIgnoring-黑名单上的输入。

对代码做了一些细微的更改。

t.prototype.checkFields = function () {
    var ignore = this.settings.emptyIgnoring, 
        numEmptyInputs = 0;
    this.$container.find('.form-fieldset:visible').each(function (i, node) {
        var $node = $(node), 
            $inputs = $node.find('input[type="text"], input[type="password"], input[type="email"]'),
            writeId = $inputs.data('write-id');
        //writeId is not in the Array `settings.emptyIgnoring`
        //this node contains at least one text-, password- or email-input field
        //the input is not disabled (actually only checks the first element)
        //the input contains some none-whitespace characters
        if(ignore.indexOf( writeId ) === -1 && $inputs.length > 0 && !$inputs.prop('disabled') && !$inputs.val().trim()){
            numEmptyInputs++;
            $node.addClass('is-js-error');
            $node.find('.form-fieldset__error').html('Заполните поле');
        }
    }); 
    return numEmptyInputs;
},