跳到正文
Simon Willison·· 2026-10-18AI 评分34

用 document.currentScript 实现内联渲染

Inline rendering with document​.currentScript

AI 导读

Lean Rada 介绍一种利用 document.currentScript 属性的内联渲染技巧。通过定义快捷函数 $=(...n)=>document.currentScript.replaceWith(...n),可将内联脚本直接替换为模板内容,实现极简模板语言。该方法支持在 HTML 中直接嵌入动态内容,如输出当前年份。

来源:Simon Willison · simonwillison.net