Editor.setComponents(html)和pageManager.select(pageId)未加载js脚本
感谢你报告,@NoumanAhmad-Braqsol。 关于 [QUESTIONS] editor.setComponents(html) 和 pageManager.select(pageId) 不要加载 js 脚本 的建议很棒!虽然这个具体功能还没有出现在核心 API 中,但有几种方法可以实现类似的行为。 使用事件系统: “JavaScript editor.on('component:update', (component) => { 你的逻辑 }); ``` 替代方法: 听取“selector:add”以获取CSS选择器更改 使用“selector:custom”来表示自定义规则 利用“change:*”事件进行细致跟踪...
阅读下方完整回答 ↓问题
嗨,@artf
- 据我所知,allowScripts:1 允许 grapesjs 加载脚本。我第一次加载着陆页时,它运行正常。它能加载所有JavaScript。之后,当我使用 editor.setComponents(html) 或 pageManager.select(pageId) 来处理与 LandingPage 使用的同一个 HTML 字符串时,JavaScript 不行。
const editor = grapes.init({
容器:“#gjs”,
附录点击:1,
allowScripts:1,
jsInHtml: true,
fromElement: false,
})
- appendOnClick:1 这样可以让该块添加 OnClick,这样就能正常工作了。但它将块附加到所选元素 中。 我的问题是,在Onclick的特定位置上该给谁添加一个块。 实际上,我想把该块作为所选元素的下一个兄弟块添加。
回答(1)
感谢你报告,@NoumanAhmad-Braqsol。 关于 [QUESTIONS] editor.setComponents(html) 和 pageManager.select(pageId) 不要加载 js 脚本 的建议很棒!虽然这个具体功能还没有出现在核心 API 中,但有几种方法可以实现类似的行为。 使用事件系统: “JavaScript editor.on('component:update', (component) => { 你的逻辑 }); ``` 替代方法: 听取“selector:add”以获取CSS选择器更改 使用“selector:custom”来表示自定义规则 利...
相关问答
通过相似的问题讨论继续研究。
问题 #6603
属性值中不逃避 & 符号
GrapesJS版本 [x] 我确认使用最新版本的GrapesJS 你用的是什么浏览器? Chrome v142.0.7392.0 (canary) 可复制演示链接 https://jsfiddle.net/xce183nm/1/ 描述一下那个虫子 如何复现这个漏洞? 创建一个...
问题 #3496
成就:标记组件为脏
你想给GrapesJS添加什么? 组件应该能够标记自己为脏,触发“onbeforeunload”警告信息。 详细描述你的功能需求详细 我有一个(自定义)文本组件,用户可以输入任意文本。我把数据存储在服务器上,我想要自动保存。不过,我不希望服务器因为每一个字符都被联系到文本组件,...
问题 #3447
JavaScript 因编码问题无法使用
1 - 我复制了打字文本组件代码,而不是演示HTML代码; 2 - 并增加了allowScripts:1; 你可以在这里看到示例:http://bashworld.ru/demo.html 点击 查看代码,我们会看到许多 JS 编码字符。 我该如何解决这个问题?我需要解码所有...
问题 #6409
手机上无法拖动移动组件
葡萄JS版本 [x] 我确认使用最新版本的GrapesJS 你用的是什么浏览器? Chrome v133 可复制演示链接 https://jsfiddle.net/2hjdrb7L/1/ 描述一下那个虫子 如何复现这个漏洞? 用grapesjs v0.22.x和grapesjs...
与此问题匹配的付费插件
根据问题关键词和标签相关性精选,助你更快交付。
正在加载付费插件推荐……
相关教程
关于同一主题的深入指南。
教程
Vanilla GrapesJS vs GrapesJS With Plugins: What You Actually Get Out of the Box (2026)
New to GrapesJS? See exactly what the stock editor gives you, where it falls short, and which plugins close the gaps — a beginner-friendly 2026 comparison
教程
Lighthouse for GrapesJS: Audit Accessibility and SEO Without Leaving the Editor
Live WCAG 2.1/2.2 accessibility auditor + SEO manager for GrapesJS. Every finding is bound to the exact component — click to select, then one-click fix.
教程
GrapesJS DevTools: A Developer Panel Inside Your Editor
If you've ever debugged GrapesJS with console.log(editor.getSelected()) and a dozen throwaway event listeners — this post is for you.
浏览插件分类
直接跳转到市场上的插件分类页面。