简体   繁体   English

如何在字符串中编写 html 代码以创建代码片段?

[英]How write html code in string to create a code snippet?

<Modal show={props.show} onHide={() => props.close()} size="lg" centered aria-labelledby="contained-modal-title-vcenter" >
            <Modal.Header closeButton>
                <Modal.Title>Modal heading</Modal.Title>
            </Modal.Header>
            <Modal.Body>
                some random text................
                        
                You include the script with the following code:
                  <script src='script.js'></script>

                        
            </Modal.Body>
            <Modal.Footer>
                <Button variant="secondary" onClick={() => props.close()}>
                    Close
                </Button>
                <Button variant="primary">
                    Download
                </Button>
            </Modal.Footer>
        </Modal>

In the above code I want the script tag line in Modal.Body to be displayed as text but instead the code is being executed.在上面的代码中,我希望Modal.Body中的脚本标记行显示为文本,而是执行代码。 I tried enclosing the script tag in span but its still doesn't work, same is happening with <input> and <canvas>我尝试将脚本标签包含在span中,但它仍然无法正常工作, <input><canvas>也是如此

Replace the Less than sign ( < ) with &lt;小于号( < ) 替换为&lt; and similarly replace the Greater than sign ( > ) with &gt;并类似地将大于号( > ) 替换为&gt; . .

So your code will become:所以你的代码将变成:

 &lt;script src='script.js'&gt;&lt;/script&gt;

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

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