React设置IFRAME SRC从按钮单击

发布于 2025-02-09 12:51:45 字数 555 浏览 3 评论 0原文

尝试设置将将URL末端更改为“ Light”或“ Dark”并刷新iframe的按钮或切换开关

const url = ("http://localhost/ij3&theme=")
const mode = ['light', 'dark']

const TestPage = () => (
    <Card>
        <Switch defaultChecked />
        <Button
            onClick={() => { }}
            label="dark">
        </Button>
        <IframeResizer
            src={url + mode}
            style={{ width: '1px', width: '100%'}}
        />
    </Card>
);

export default TestPage;

Trying to set a button or toggle switch that will alter end of the url to "light" or "dark" and refresh the iframe

const url = ("http://localhost/ij3&theme=")
const mode = ['light', 'dark']

const TestPage = () => (
    <Card>
        <Switch defaultChecked />
        <Button
            onClick={() => { }}
            label="dark">
        </Button>
        <IframeResizer
            src={url + mode}
            style={{ width: '1px', width: '100%'}}
        />
    </Card>
);

export default TestPage;

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

冷弦 2025-02-16 12:51:45

使模式作为react中的状态,因此每当会更改时,重新渲染时也将更新iframe src

make mode as state in react so whenever it will change, on re-render it will also update the iframe src

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文