简体   繁体   English

在javascript小书签中编写HTML布局/模板

[英]Writing HTML layout/template within javascript bookmarklet

I have a bookmarklet which creates a UI for the user to interact with. 我有一个书签,可以为用户创建一个与用户进行交互的UI。 Currently, I have been using $('<element>').addClass().css({..}); 当前,我一直在使用$('<element>').addClass().css({..}); , but that becomes hard to maintain. ,但这很难维持。 Is there a better way to do this? 有一个更好的方法吗?

I have also tried doing something like 我也尝试做类似的事情

var html = "<div class='someclass'>";
html += "<more html/>";
html += "</div>"

Which is also incredibly hard to maintain. 这也很难维护。 Is there a way I can write html within javascript, or a library like jade that i can use WITHIN a javascript bookmarklet? 有没有一种方法可以在javascript内编写html,或者可以在javascript书签中使用WITH的类似玉的库?

Yes, there is a Domain Specific Language implementation in JavaScript to allow you to write more expressive HTML in JavaScript called Pithy . 是的,JavaScript中有一个特定于域的语言实现,可让您用称为Pithy的 JavaScript编写更具表现力的HTML。

Please remember that writing large amounts in Pithy is maybe not a good idea and you rather want to use a proper client side templating engine such as DustJS or many others. 请记住,用Pithy编写大量代码可能不是一个好主意,而您想使用适当的客户端模板引擎,例如DustJS许多其他引擎。

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

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