1
我有一個顯示/隱藏div腳本,當用戶單擊以顯示div時也會記錄信息。日誌工作正常,div顯示/隱藏,但只有第二次點擊,它沒有用於在我添加日誌功能之前做到這一點。 我是一個完整的JS/JQuery noob,請解釋我出錯的地方!JQuery需要點擊兩次才能啓動腳本
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script type="text/javascript">
function showAnswer(whichLayer,id,lang){
var whichLayer, id, lang;
if(document.getElementById(whichLayer).style.display =="none"){
document.getElementById(whichLayer).style.display = "block";
$.post("../../logclick.php", {id: id, lang: lang});
}else{
document.getElementById(whichLayer).style.display = "none";
}
}
</script>
編輯:調用函數的代碼。
<div class="question">
<a href="javascript:showAnswer('2111692','1692','en')">Click here</a>
</div>
<div id="2111692" class="answer">Answer shows here.</div>
樣式表:
.answer {
clear: both;
margin-left: 30px;
display: none;
}
這個事件是如何連接起來的? –
編輯帖子以添加呼叫功能。 – Marine
你確定你的'style.display'確實是'none'嗎? – putvande