简体   繁体   English

按钮在我的HTML的某些部分中不起作用

[英]Button not working in certain parts of my HTML

I have a button id="getstarted" located near the top and the bottom of my HTML. 我的HTML顶部和底部附近有一个id="getstarted"按钮。 The button near the top works, but the one near the bottom does not work. 顶部附近的按钮有效,但底部附近的按钮无效。 They are formatted exactly the same. 它们的格式完全相同。 I want both buttons to work. 我希望两个按钮都能正常工作。

Here is my code. 这是我的代码。 **edited code. **编辑代码。 I added onclick="window.location.href = 'getstarted.html';" 我添加了onclick="window.location.href = 'getstarted.html';" to my buttons. 我的按钮。 now the first button works, but the second one does not work. 现在,第一个按钮可以使用,但是第二个按钮不能使用。 how do I get the second button to work? 如何使第二个按钮起作用?

 $(document).ready(function() { $(window).scroll(function() { if ($(this).scrollTop() > 70) { $('#header').fadeIn(500); } else { $('#header').fadeOut(500); } }); }); $(document).ready(function() { $(window).scroll(function() { if ($(this).scrollTop() > 70) { $('#pricing').css("color", "#000"); } else { $('#pricing').css("color", "#FFF"); } }); }); // slideshow $(document).ready(function() { $("#laptopslideshop > div:gt(0)").hide(); setInterval(function() { $('#laptopslideshop > div:first') .fadeOut(500) .next() .fadeIn(500) .end() .appendTo('#laptopslideshop'); }, 3000); }); 
 @import url('https://fonts.googleapis.com/css?family=Nunito+Sans'); * { box-sizing: border-box; margin: 0; padding: 0; } #header { position: fixed; top: 0px; width: 100%; height: 84px; background-color: #FFFFFF; color: #000; z-index: 1; display: none; } @media (max-width: 768px) { #header { height: 60px; } } #main { height: 100vh; width: 100%; background: url(Images/teamchat.jpg) no-repeat center; background-size: contain; background-size: cover; } .headerContents { text-align: right; height: 100%; width: 100%; float: right; z-index: 2; position: fixed; } .headerpandc { margin-right: 18%; margin-top: 17px; position: relative; } @media (max-width: 768px) { .headerpandc { margin-right: 4%; margin-top: 14px; } } #pricing { font-family: Nunito Sans; margin-right: 55px; font-weight: 800; letter-spacing: 0.1em; font-size: 18px; text-decoration: none; color: #FFF; transition: 0.6s; } @media (max-width: 768px) { #pricing { font-size: 12px; margin-right: 3%; } } @media (max-width: 355px) { #pricing { display: none; } } #pricing:hover { text-decoration: underline; } #pricing:active { color: #000; } #getstarted { font-family: Nunito Sans; background-color: #5a52ff; border-radius: 10px; border: none; color: white; padding: 11px 25px; text-align: center; font-size: 18px; transition: 0.3s; text-decoration: none; cursor: pointer; font-weight: 800; letter-spacing: 0.05em; outline: none; } @media (max-width: 768px) { #getstarted { padding: 8px 15px; font-size: 12px; } } #getstarted:hover { background-color: #3d33ff; } #getstarted:active { transform: translateY(2px); box-shadow: 0 1px #666; } #telosdesignlogo { float: left; height: 30px; margin-left: 18%; margin-top: 6px; } @media (max-width: 768px) { #telosdesignlogo { margin-left: 4%; height: 23px; } } /*main text*/ #mainbox { height: 470px; width: 500px; text-align: left; position: relative; top: 250px; left: 28%; font-family: Nunito Sans; color: #FFF; } #hitelos { font-size: 2.5em; font-weight: lighter; } #maintext { font-weight: 800; font-size: 3.5em; } #mainpricing { z-index: 5; } /* Laptop slideshow begins */ #laptopslideshop { position: relative; margin-top: 50px; width: 240px; height: 240px; padding: 10px; box-shadow: 0 0 20px rgba(0, 0, 0, 0.4); } .mySlides { position: absolute; width: 100%; } 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script> <div id="header"></div> <div class="headerContents"> <div class="headerpandc"> <a id="pricing" href="pricing.html">Pricing</a><button id="getstarted" onclick="window.location.href = 'getstarted.html';">Get Started</button> <a href="index.html"><img src="Images/TelosLogo with text.png" href="index.html" alt="TelosDesign" id="telosdesignlogo" /></a> </div> </div> <div id="main"> <div id="mainbox"> <div id="hitelos"> Hi! We're Telos. </div> <div id="maintext"> Beautiful websites tailored to your unique business. </div> <button id="getstarted" onclick="window.location.href = 'getstarted.html';">Get Started</button> </div> </div> <div id="laptopslideshop"> <div> <img class="mySlides" src="Images/laptoppic1test.png" alt="Laptop and Phone" /> </div> <div> <img class="mySlides" src="Images/laptoppic2test.png" alt="Laptop and Phone" /> </div> </div> 

id should be unique to an element(just one), use a class instead id对于一个元素应该唯一(仅一个),请使用class

In your code you use javascript(jquery) to control href , not html, see onclick . 在代码中,您使用javascript(jquery)来控制href而不是html,请参见onclick

<button id="getstarted" onclick="window.location.href = 'getstarted.html';">

The javascript is taking in consideration only the first element because no other element with the same id should exist. javascript仅考虑第一个元素,因为不应该存在具有相同id其他元素。

-- -

I see that you have also: 我看到你也有:

  <script type="text/javascript" src="app.js"></script>

What this code is doing ? 这段代码在做什么?

Check the web browser console for JavaScript errors from other sources/code. 检查Web浏览器控制台中是否有其他来源/代码的JavaScript错误。

Try with this code 尝试使用此代码

  <a id="pricing" href="http://google.com">Pricing</a> <a href="http://google.com" target="_blank"><button id="getstarted">Get Started</button></a> <a href="index.html"> <img src="Images/TelosLogo with text.png" href="http://google.com" alt="TelosDesign" id="telosdesignlogo"></a> 

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

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