基于GET参数的动态href

问题描述

我想在HTML中创建一个链接,该链接的href根据GET参数而变化(例如 link

我以<a href="?url">text</a> 的身份尝试

const Discord = require('discord.js');

module.exports.run = async (bot,message,args) => {
 let helpArray = message.content.split(' ');
 let helpArgs = helpArray.slice(1);

 if (helpArgs[0] === 'gaming') {
  return message.reply('Gamings');
 }

 if (!helpArgs[0]) {
  const embed = new Discord.MessageEmbed()
   .setColor(`#f900ff`)
   .setTitle(`**Dragonite Commands:**`)
   .addFields(
    {
     name: '**:police_officer: Moderation:**',value:
      '**`!mute`**,**`!kick`**,**`!ban`**,**`!unban`**,**`!nickname`**,**`!clear`**',},{
     name: '**:sparkles: Misc:**',value:
      '**`!avatar`**,**`!ping`**,**`!info`**,**`!user`**,**`!server`**,**`!mute`**',}
   )
   .setFooter(
    'Dragonite | Requested by ' + message.author.tag,'https://i.imgur.com/3Oxc3I8.png'
   );

  return message.channel.send(embed);
 }

 if (helpArgs[0]) {
  let command = helpArgs[0];

  if (bot.command.has(command)) {
   command = bot.commands.get(command);
   const embed = new Discord.MessageEmbed()
    .setTitle(`Command Help: ${command.config.name}`)
    .setColor(`#f900ff`).setDescription(`
                **Name: ${command.config.name} || "N/A"
                **Description: ${command.config.description} || "N/A"
                **Usage: ${command.config.usage} || "N/A"
                **Example: ${command.config.example} || "N/A"
                `);
  } else
   return message.channel.send("**This command isn't available :warning:!**.");
 }
};
module.exports.help = {
 name: 'help',description: "Check a Dragonite's commands.",usage: 'user [@user | user ID]',example: 'user LeRegedit#1281',};

但这不起作用


Here is a gif of how it should work

对不起,我的英语

解决方法

我了解到您正在尝试通过从GET参数动态获取网址来填充定位链接的“ href”属性。

这可以在JavaScript的帮助下完成。我找到了一个示例in another Stack Overflow question,并使其适合您的用例。在同一线程中,您还将找到一些其他方法的很好示例。

尝试以下代码段:

   <a id="myLink" href="">Text</a>

   <script>
      const urlParams = new URLSearchParams(window.location.search);
      const myParam = urlParams.get('link');
      const myLink = document.getElementById('myLink');

      if(myParam) {
         myLink.href = myParam; /* The URL given as a parameter */
      } else {
         myLink.href = '#0'; /* If no parameter,the link leads nowhere */
      }
   </script>

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...