javascript - Bootstrap modal 不能在 React 打字稿应用程序中工作,但在小提琴上工作
问题描述
根据我目前的研究:
这是一个调试版本https://preprod-ansaar.web.app/
我在我的中实现了一个引导模式app.tsx
:
import React from 'react';
const app: React.FC = () => {
return (
<div>
<button id="btn1">Show Modal</button>
<br />
<button data-onclick="alert('Button Clicked')">Another Button</button>
<div className="modal fade" id="myModal" data-tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
<div className="modal-dialog" role="document">
<div className="modal-content">
<div className="modal-header">
<button className="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 className="modal-title" id="myModalLabel">Modal Title</h4>
</div>
<div className="modal-body">
Modal Body
</div>
<div className="modal-footer">
<button className="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
</div>
);
}
export default app;
我index.css
的是:
#myModal {
position: relative;
}
.modal-dialog {
position: fixed;
width: 100%;
margin: 0;
padding: 10px;
}
在index.html
我有:
<script>
$('#btn1').click(function () {
// reset modal if it isn't visible
if (!($('.modal.in').length)) {
$('.modal-dialog').css({
top: 0,
left: 0
});
}
$('#myModal').modal({
backdrop: false,
show: true
});
$('.modal-dialog').draggable({
handle: ".modal-header"
});
});
</script>
相同的代码正在生成一个可拖动的模式,同时保持背景在小提琴上可用
这在我的 React 应用程序中不起作用,有人可以指导吗?
解决方案
推荐阅读
- powershell - 是否可以使用 Copy-Item 从源目录中仅复制几个文件?
- wpf - Powershell GUI未将单选按钮注册为单击
- javascript - 在不了解其属性的情况下比较 JSON 对象
- angular - 当来自 Origin 的资源为 10 个或更多文件时,不存在“Access-Control-Allow-Origin”标头,但在 9 个或更少时很好
- github - 我可以将外部位置用作 git-lfs 的单独服务器吗?
- google-sheets - 使用importXML函数获取股票的扇区数据
- linux - 错误无法加载库“/usr/pgsql-11/lib/postgres_fdw.so”
- java - jar 可执行文件在 Netbeans maven 项目中运行时功能失调
- r - 使用数据表的计算列在 ggplot 条形图中添加计算值
- php - 无法使用 Laravel 工厂为数据透视表中的非关系列设置值