我有一个按钮,当点击时会打开一个新的标签,其中包含javascript中指明的网址。但是,一旦我把这个按钮放在figcaption中它可以点击,但javascript不起作用。这是代码:
<div class="container-top-pics">
<div class="row-top-pics">
<div class="column-left-pic">
<div class="col-inner">
<img src="Images/sf-downtown.jpg">
<figcaption>
WELCOME TO THE<br />
<h1>DEAL GUIDE</h1><br />
</figcaption>
</div>
</div>
<div class="column-right-pic">
<div class="col-inner">
<img src="Images/sf-ad.jpg">
<figcaption>
SPECIAL DEALS<br />
<h1>GET THEM</h1>
<h2>NOW</h2>
<button type="button" id="button-ad" class="button-ad" onclick="OpenInNewTab()">RESERVE NOW</button>
</figcaption>
</div>
</div>
</div>
</div>
CSS:
.container-top-pics {
width: 80%;
margin: 0 auto;
max-width:1140px;
}
img {
max-width:100%;
}
.column-right-pic {
float:left;
width:29%;
position: relative;
}
.column-right-pic figcaption {
font-family: "Avenir";
letter-spacing: 1px;
color: #FFF;
font-size: 1vw;
font-weight: 100;
text-align: center;
position: absolute;
z-index: 1000;
height: 100%;
width: 100%;
top: 0;
padding: 0 0 0 0;
line-height: 5em;
}
.column-right-pic h1 {
font-family: "Avenir";
letter-spacing: 4px;
color: #FFF;
font-style: normal;
font-weight: 100;
text-align: center;
font-size: 2vw;
width: 100%;
padding: 0% 0 0 0 ;
line-height: 0;
}
.column-right-pic h2 {
font-family: "Avenir";
letter-spacing: 4px;
color: #FFF;
font-style: normal;
font-weight: 100;
text-align: center;
font-size: 2vw;
width: 100%;
padding: 0% 0 0 0 ;
line-height: 1.7em;
}
.column-right-pic .button-ad {
font-family: "Helvetica Neue";
letter-spacing: 1px;
color: #FFF;
font-style: normal;
font-weight: 500;
text-align: center;
font-size: .8vw;
width: 45%;
height: 10%;
padding: 0% 0 0 0 ;
line-height: 1.7em;
background-image: url(../Images/button-reserve.jpg);
border:none;
}
.button-ad:hover {
background-image: url(../Images/button-reserve-hover.jpg);
cursor: pointer; cursor: hand;
}
.button-ad:active {
background-image: url(../Images/button-reserve-click.jpg)
}
使用Javascript:
document.getElementById('button-ad').onclick = function OpenInNewTab(url) {
var win = window.open('http://www.example.org');
win.focus();
}
答案 0 :(得分:0)
.column-right-pic .button-ad {
font-family: "Helvetica Neue";
letter-spacing: 1px;
color: #FFF;
font-style: normal;
font-weight: 500;
text-align: center;
font-size: .8vw;
width: 45%;
border-style: none;
border-top: 2px solid #ffffff;
/*height: 10%;*/
padding: 0% 0 0 0 ;
line-height: 1.7em;
background-image: url(../Images/button-reserve.jpg);
/*background-color: #ff0000;*/
background-color: transparent;
}