微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

基于GET参数的动态href

如何解决基于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>

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。