【发布时间】:2019-12-03 17:27:52
【问题描述】:
我得到一个错误。 我添加了一些代码,并想通过我的代码了解原因 它不工作。 我不能使用反应带。请建议我们是否可以在反应中使用 Bootstrap 模态。
我得到一个错误。 我添加了一些代码,并想通过我的代码了解原因 它不工作。 我不能使用反应带。请建议我们是否可以在反应中使用 Bootstrap 模态。 下面是我的代码
import React from 'react';
import $ from 'jquery';
window.jQuery = $;
window.$ = $;
global.jQuery = $;
class Modal extends React.Component {
constructor(props) {
super(props);
}
componentDidMount() {
$('#myModal').on('shown.bs.modal', function () {
$('#myInput').trigger('focus');
});
}
render()
{
return (
<div>
<div className="bd-example">
//Button code
<button type="button" className="btn btn-primary " data-toggle="modal" data-target="#exampleModalLive">
Launch demo modal</button>
//Modal code
<div className="modal" id="exampleModalLive" tabindex="-1" role="dialog" aria-labelledby="exampleModalCenterTitle" aria-hidden="true">
<div className="modal-dialog modal-dialog-centered" role="document">
<div className="modal-content">
<div className="modal-header">
<h5 className="modal-title" id="exampleModalCenterTitle">Modal title</h5>
<button type="button" className="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div className="modal-body">
...
</div>
<div className="modal-footer">
<button type="button" className="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="button" className="btn btn-primary">Save changes</button>
</div>
</div>
</div>
</div>
</div>
</div>
);
}
}
export default Modal;
【问题讨论】:
-
最好不要在react项目中添加
jquery。发布您的代码,以便我们提供帮助。 -
我不能在我的工作中使用 react-strap。因为它不属于 Bootstrap。
-
这种情况下你需要通过CDN使用jquery,在index.html文件中添加
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>。 -
发布你的代码,你是如何使用模态的?
标签: javascript jquery html reactjs twitter-bootstrap-3