我以前有jquery-2.2.x
,并且代码运行良好。现在,我更新了jquery-3.3.x
,并开始获取错误datepicker()
函数不存在。搜索该错误后,得知它需要moment.js
和bootstrap.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;