错误:升级jquery版本后,bootstrap的JavaScript需要jQuery

时间:2019-05-13 12:45:16

标签: javascript jquery node.js twitter-bootstrap bootstrap-datepicker

我以前有jquery-2.2.x,并且代码运行良好。现在,我更新了jquery-3.3.x,并开始获取错误datepicker()函数不存在。搜索该错误后,得知它需要moment.jsbootstrap.js。因此,添加这些软件包后,我得到了错误: Error: Bootstrap's JavaScript requires jQuery

尽管我正在导入jquery

当我使用jquery-2.2.x时,此代码正在运行,没有任何错误,但是与jquery-3.3.x相同的代码不起作用,并且未定义错误datepicker()函数。

const React = require('react');
const $ = require('jquery');
require('bootstrap-datepicker/dist/css/bootstrap-datepicker.min.css');
require('bootstrap-datepicker/dist/js/bootstrap-datepicker.min.js');
require('styles/InputField.css');
/*
    Renders a single input field with label and inputBox
    Attributes
    1)labelText -> text for the label
    2)inputId -> Id for the input box
    3)inputPlaceholder -> placeholder for the input
    4)isDate -> if the field is for date activate the jquery datepicker
    Returns a div
*/
class InputField extends React.Component {

    constructor(props) {
        super(props);
        this.state = {
            datepickerEnabled: false
        }
    }

    // If the component is mounted and it is a date field activate the datepicker
    componentDidMount() {
        if(this.props.isDate === 'true') {
            $('#' + this.props.inputId).datepicker({dateFormat: 'mm/dd/yy'});
            this.setState({
                datepickerEnabled: true
            });
        }
    }

    render() {
        return (
            <div>
                <label htmlFor={this.props.inputId}> {this.props.labelText} </label>
                <input type='text' id={this.props.inputId} placeholder={this.props.inputPlaceholder} className='form-control'/>
            </div>
        );
    }
}

module.exports = InputField;

0 个答案:

没有答案