如何用Jade执行js? [英] How to execute js with Jade?

查看:80
本文介绍了如何用Jade执行js?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何在渲染之前执行js?

i was wondering how to execute js before rendering?

操作失败

-#{somejs} // Outputs just the js-code
p #{somejs()} // Executes the js-code, but doenst render the html

//在EJS中,我只是写了。但是我该如何使用节点呢?

// In EJS I just write. But how can i do this with node?

<%- somejs() %>

//我尝试使用express-messasges(https://github.com/visionmedia/express -messages)而不是ejs

// I try to use express-messasges (https://github.com/visionmedia/express-messages) with Jade instead of ejs

推荐答案

以下两种方法对我都有效:

The following both work for me:

- var test = Math.sqrt(16);
  div #{test}

div#{Math.sqrt(25)}

如果可能,请发表您的文章 somejs()?您确定它会产生HTML字符串吗?

If possible, would you please post your somejs()? Are you certain that it is producing a HTML string?

这篇关于如何用Jade执行js?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆