我有這些功能,一旦鏈接被點擊就執行。出於某種原因,儘管鏈接一旦被點擊,它就不會打開。你必須雙擊。頁面訪問後,只需要點擊一次鏈接。我如何解決這個問題,只需要點擊一下即可。單擊和雙擊問題
function indexClick() {
$("#home").on("click", function() {
$('.indexPicWrapper').css('display', 'block');
$('.aboutPicWrapper').css('display', 'none');
})
}
function aboutClick() {
$("#about").on("click", function() {
$(".indexPicWrapper").css("display", "none")
$('.contactPicWrapper').css('display', 'none');
$('.aboutPicWrapper').css('display', 'block');
})
}
nav {
height: 50px;
background-color: #eaeaea;
line-height: 50px;
text-align: center;
}
.indexPicWrapper {
min-height: 100%;
height: 100%;
width: 100%;
overflow-y: hidden;
background: #FFA10D;
position: absolute;
}
.aboutPicWrapper {
display: none;
position: absolute;
height: 100%;
width: 100%;
overflow-y: hidden;
background-color: #FF510D;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<nav>
<a id="home" onclick="indexClick()" class="indexLink" href="#">Home</a>
<a id="about" class="aboutLink" onclick="aboutClick()" href="#">About</a>
</nav>
<div class="indexPicWrapper">
<h1>Things...</h1>
</div>
<div class="aboutPicWrapper">
<h1>About...</h1>
</div>
加上'返回true;'給事件偵聽器的結束,這將使環節進行它們的默認行爲。 – micnic