Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在显示模式警报消息,相同的消息将出现在多个页面上。我不想维护<div id="modal">contents</div>所有这些页面。任何人都可以推荐如何使用 JS 将我的代码提供给多个页面吗?还是我坚持将代码插入每个代码?想法?
<div id="modal">contents</div>
您可以将内容放入主 JavaScript 文件,然后从那里调用它。例如,当您的all.js文件包含在所有页面中时,请将其添加到该文件中:
all.js
var modalContents = '<div id="modal">contents</div>';
并且在调用模态警报时,将modalContents变量加载到其中。
modalContents