简体   繁体   English

如何使用react js在右上角制作带有关闭图标的按钮

[英]how to make button with close icon in right corner using react js

in reactjs在 reactjs 在此处输入图像描述 how to make button with close icon in right corner using react js.如何使用 React js 在右上角制作带有关闭图标的按钮。 in my below code when i run the page i want to make button with close icon in right corner.when i click cross icon then button is closed.在我下面的代码中,当我运行页面时,我想在右上角制作带有关闭图标的按钮。当我单击十字图标时,按钮关闭。

How can we do that.anyone please help me out.i am stuck on that.its very thankful.我们怎么能做到这一点。任何人都请帮帮我。我被困住了。非常感谢。

how can we do that this type button which i have posted i want to make this type when i run the page using reactjs.anyone know about that using reactjs我们怎么能做到这种类型的按钮,我已经发布了我想在我使用 reactjs 运行页面时制作这种类型。任何人都知道使用 reactjs

check here in my code.in here i wan to make cross icon with right corner https://codesandbox.io/s/awesome-violet-ddpf9?file=/src/index.js在我的代码中检查这里。在这里我想用右上角https://codesandbox.io/s/awesome-violet-ddpf9?file=/src/index.js制作十字图标

import React from "react";
import ReactDOM from "react-dom";

// import "./styles.css";

class App extends React.Component {
  render() {
    return (
      <div className="App">
        <button
          className="btn btn-danger"
          // onClick={() => {
          //   if (window.confirm("Delete the item?")) {
          //     let removeToCollection = this.removeToCollection.bind(this, 121);
          //     removeToCollection();
          //   }
          // }}
        >
          Warning Meaasge with close option
        </button>
      </div>
    );
  }

  removeToCollection(key, e) {
    console.log(key);
  }
}

const rootElement = document.getElementById("root");
ReactDOM.render(<App />, rootElement);

Created a custom Modal component and injected it in App component.创建了一个自定义的Modal组件并将其注入到App组件中。

Stackblitz - https://stackblitz.com/edit/reactjs-example1-yz2mez?file=index.js Stackblitz - https://stackblitz.com/edit/reactjs-example1-yz2mez?file=index.js

Note :- You can replace the html mark up using bootstrap structure if you need to.注意:- 如果需要,您可以使用引导结构替换 html 标记。 If you want to open the dialog once closed, you can uncomment the p tag i the root component.如果要在关闭后打开对话框,可以取消注释根组件中的p标记。

You can create a div and style accordingly, if you want to perform a specific function on onClick, then you can use event.target.id .您可以相应地创建一个 div 和样式,如果您想在 onClick 上执行特定的 function,那么您可以使用event.target.id I have used the state to show and hide button.我使用了 state 来显示和隐藏按钮。

Sample Code - https://codesandbox.io/s/close-icon-at-top-5czwf?file=/src/index.js示例代码 - https://codesandbox.io/s/close-icon-at-top-5czwf?file=/src/index.js

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM