【问题标题】:Using a jquery form with React使用带有 React 的 jquery 表单
【发布时间】:2016-04-28 10:54:01
【问题描述】:

我是使用 ReactJS 的新手。我有一个在 JQuery 上编写的表单,我想在 React 组件上制作它。请问我该怎么做?

(function($) {

"use strict";

var form = {
    field_input: $('.field-input'),
    init: function() {
        this.transformInput();
    },
    transformInput: function() {
        this.field_input.focus(function(){
            $(this).parent().addClass('is-focused has-label');
        });

        this.field_input.blur(function(){
            var $parent = $(this).parent();
            if($(this).val() === ''){
                $parent.removeClass('has-label');
            }
            $parent.removeClass('is-focused');
        });

        this.field_input.each(function(){
            if($(this).val() !== ''){
                $(this).parent().addClass('has-label');
            }
        });
    }
};

window.form = form;
})(jQuery);

【问题讨论】:

    标签: javascript jquery reactjs react-jsx jsx


    【解决方案1】:

    你可以写componentDidMount查看this

    【讨论】:

      猜你喜欢
      • 2019-04-03
      • 1970-01-01
      • 2011-04-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-05-04
      相关资源
      最近更新 更多