3 回答
TA贡献2041条经验 获得超4个赞
该按钮不起作用,因为它取决于jQuery,因为您需要jQuery在代码中安装,但我不建议您jQuery在代码中安装。
为此,您可以使用react-bootstrap
<button className="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span className="navbar-toggler-icon" />
</button>
TA贡献1806条经验 获得超5个赞
您需要将您的button点击与其处理程序连接起来
基本用法假设您使用有状态或基于类的组件。
const onClickHandler = (e) =>{
console.log(e);
}
render(){
<button onClick={this.onClickHandler}>Click Me!</button>
}
TA贡献1834条经验 获得超8个赞
所以我必须在index.html中导入jquery,这就是我导入它的方式:
<!DOCTYPE html>
<html dir="ltr">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.3/css/bootstrap.min.css" integrity="sha384-Zug+QiDoJOrZ5t4lssLdxGhVrurbmBWopoEl+M6BdEfwnCJZtKxi1KgxUyJq13dy" crossorigin="anonymous">
</head>
<body>
<div id="root"></div>
<!-- Turbo library imports: jQuery, Turbo CDN, sample app.js -->
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.3/js/bootstrap.min.js" integrity="sha384-a5N7Y/aK3qNeh15eJKGWxsqtnX/wWdSZSKp+81YjTmS15nvnvxKHuzaWwXHDli+4" crossorigin="anonymous"></script>
<script type="text/javascript" src="/dist/js/vendor.min.js"></script>
<script type="text/javascript" src="https://cdn.turbo360-dev.com/dist/turbo.min.js"></script>
<script type="text/javascript" src="/dist/bundle/commons.js"></script>
<script type="text/javascript" src="/dist/bundle/app.js"></script> <!-- React code bundle -->
</body>
</html>
- 3 回答
- 0 关注
- 127 浏览
添加回答
举报