html中引入js文件使用其变量,如何从HTML文件到JS文件使用JS变量?

这是怎么回事 ?

我正在用express.js开发一个网站,我想知道如何将JavaScript中的变量从ejs文件导出到js文件?

ejs文件:

let channelText = guild.channels.cache.filter(channel => channel.type == 'text');

channelText.forEach((channel)=>{

%>

#

我想将strUser变量导出到我的js文件夹中。

我的js文件:

// Settings endpoint.

app.post("/dashboard/:guildID", checkAuth, async (req, res) => {

// We validate the request, check if guild exists, member is in guild and if member has minimum permissions, if not, we redirect it back.

const guild = client.guilds.cache.get(req.params.guildID);

if (!guild) return res.redirect("/dashboard");

const member = guild.members.cache.get(req.user.id);

if (!member) return res.redirect("/dashboard");

if (!member.permissions.has("MANAGE_GUILD")) return res.redirect("/dashboard");

// We retrive the settings stored for this guild.

var storedSettings = await GuildSettings.findOne({ gid: guild.id });

if (!storedSettings) {

// If there are no settings stored for this guild, we create them and try to retrive them again.

const newSettings = new GuildSettings({

gid: guild.id

});

await newSettings.save().catch(()=>{});

storedSettings = await GuildSettings.findOne({ gid: guild.id });

}

//var strUser = require('./templates/settings.ejs')

// We set the prefix of the server settings to the one that was sent in request from the form.

storedSettings.prefix = req.strUser //req.body.prefix

console.log(req.body.strUser)

// We save the settings.

await storedSettings.save().catch(() => {});

// We render the template with an alert text which confirms that settings have been saved.

renderTemplate(res, req, "settings.ejs", { guild, settings: storedSettings, alert: "Changement effectué avec succès." });

});

谢谢

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值