是否有一种方法可以在页面上包含多个代码之一。我尝试添加4并将其重命名,但是仍然无法正常工作,仅原来的一个仍然有效。我做错了什么吗,还是每页只能做1个工作?任何解决此问题的帮助将不胜感激。谢谢,祝您度过一个愉快的夜晚。
/* When the user clicks on the button,
toggle between hiding and showing the dropdown content */
function myFunction() {
document.getElementById("myDropdown").classList.toggle("show");
}
// Close the dropdown if the user clicks outside of it
window.onclick = function(event) {
if (!event.target.matches('.dropbtn')) {
var dropdowns = document.getElementsByClassName("dropdown-content");
var i;
for (i = 0; i < dropdowns.length; i++) {
var openDropdown = dropdowns[i];
if (openDropdown.classList.contains('show')) {
openDropdown.classList.remove('show');
}
}
}
}
.dropbtn {
cursor: pointer;
font-size: 16px;
}
.dropbtn a {
color: black;
display: block;
padding: 12px 16px;
text-decoration: none;
}
.dropdown {
margin-left: 5%;
margin-top: 25px;
position: relative;
}
.dropdown-content {
background: rgba(34, 34, 34, .25);
border: 1px solid rgba(34, 34, 34, .50);
display: none;
height: 100x;
padding: 10px 10px 10px 15px;
position: absolute;
width: 525px
}
.show {
display: table
}
<a onclick="myFunction()" class="dropbtn" style="float:right;">Search Amazon</a>
<div class="dropdown">
<div id="myDropdown" class="dropdown-content">
<script type="text/javascript">
amzn_assoc_ad_type = "responsive_search_widget";
amzn_assoc_tracking_id = "capebretons0b-20";
amzn_assoc_marketplace = "amazon";
amzn_assoc_region = "CA";
amzn_assoc_placement = "";
amzn_assoc_search_type = "search_box";
amzn_assoc_width = "auto";
amzn_assoc_height = "auto";
amzn_assoc_default_search_category = "";
amzn_assoc_theme = "light";
amzn_assoc_bg_color = "FFFFFF";
</script>
<script src="//z-na.amazon-adsystem.com/widgets/q?ServiceVersion=20070822&Operation=GetScript&ID=OneJS&WS=1&Marketplace=CA"></script>
</div>
</div>