在下面的 Jade 代码中,在条件语句中使用 JQuery 不起作用。不过如果我要放置一个脚本。 console.log($(document).width())
在代码顶部附近,它会显示,这表明 JQuery 运行正常。 if rows.length > 0
确实有效。
block content
div.issueContainer.ics
if rows.length > 0
if ($(document).width() < 1000)
p Mobile
else
p Not Mobile
//- each val in rows
//- +createIssueBox(val)
//- div.addMore
//- h1 You can be the voice of change
//- div.multButtons
//- a(href="/issues/submit").submit-button.first Submit an Issue
else
div.addMore
h1 There are no issues currently
a(href="/issues/submit").submit-button Submit an Issue
最佳答案
jQuery 是一个客户端框架,它无法在模板引擎(在您的例子中为 Jade)运行的服务器端运行。
原因console.log($(document).width())
之所以可行,是因为它位于模板生成的客户端脚本内。
关于javascript - 在 Jade 中使用 JQuery 条件不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32656545/