简体   繁体   English

您如何在 Javascript 中链接到您网站的不同部分

[英]How do you link to a different part of your website in Javascript

I created a bootstrap button.我创建了一个引导按钮。 When the button is clicked I want it to link to another page.单击按钮时,我希望它链接到另一个页面。 I created a page called bitcoin.html.我创建了一个名为 bitcoin.html 的页面。 How do I link the contents of my main page to my bitcoin.html page.如何将主页的内容链接到我的 bitcoin.html 页面。 Anchor tags seem to create a hyperlink inside the bootstrap button - I don't want that.锚标签似乎在引导按钮内创建了一个超链接——我不希望这样。 I created an onclick function and tried to redirect it.我创建了一个 onclick 函数并尝试重定向它。 But it isn't working.但它不起作用。

 function relocate { location.href = "CRYPTOAPP/bitcoin.html" }
 <!DOCTYPE html> <html lang="en" dir="ltr"> <head> <meta charset="utf-8"> <title>Cryptocurrency App</title> <link rel="preconnect" href="https://fonts.googleapis.com"> <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin> <link href="https://fonts.googleapis.com/css2?family=Montserrat:wght@400;900&family=Ubuntu:wght@300;400&display=swap" rel="stylesheet"> <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.3.1/dist/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous"> <link rel="stylesheet" href="style.css"> </head> <body> <h1>Cryptos To Watch 2022</h1> <div class="container" id="crypocontainer"> <div class="card bitcoin" id="bitcoin"> <h1> Bitcoin </h1> <img src="images/bitcoin.png" alt="bitcoin image"> <h2>Current Price </h2> <h3 class="btc"> Btc</h3> <button type="button" class="btn btn-success" onclick="relocate_bitcoin">Explore</button> </div> </body>

文件目录

Your function is called relocate but you're trying to call relocate_bitcoin in your onclick event.您的函数称为relocate ,但您试图在 onclick 事件中调用relocate_bitcoin You also need to actually call the function, ie relocate() .您还需要实际调用该函数,即relocate()

That said, you don't need a function for this—you can put that directly in the onclick:也就是说,您不需要为此使用函数——您可以将其直接放在 onclick 中:

onclick="location.href='CRYPTOAPP/bitcoin.html';"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM