0
我之前完成了這項工作,但由於某種原因,這一次它不工作,而且我一直盯着它很長時間,保證我永遠不會發現問題...在div中使用onclick函數來顯示/隱藏另一個div
我有這塊HTML,它創建一個窗體。
<div class="paymentForm">
<span class="pgHeading" style="margin: 30px 0;">Payment Information</span>
<div class="inputRedTemplate paymentType inputRoundedTop" onclick="javascript:displayPaymentFields()">
<div class="label">Credit Card</div>
</div>
<div class="inputRedTemplate paymentType">
<div class="label">Cash</div>
</div>
<div class="inputRedTemplate paymentType inputRoundedBottom" onclick="">
<div class="label">Check</div>
</div>
<div id="cashPaymentBlock">
<span>For cash payments, bills higher than $20 will not be accepted.</span>
</div>
<div id="ccPaymentBlock">
<span class="ccDisclaimer" style="margin: 30px 0;">
Your credit card transaction will be processed by your store location and you must
present your credit card to the driver at the time the store delivers your order for a
credit imprint and your signature.
</span>
<input id="card_name" name="cardName" class="inputRedTemplate inputFullWidth" placeholder="Cardholder Name" />
<input id="card_number" name="cardNumber" class="inputRedTemplate inputFullWidth" placeholder="Card Number" onkeypress="return checkNumbers(event,this)" />
<div class="error" id="err_msg" style="display: none;">Numbers only!</div>
<input id="card_type" name="cardType" class="inputRedTemplate inputFullWidth inputRoundedBottom" placeholder="Credit Card Type" />
<input id="card_expire_month" name="cardExpireMonth" class="inputRedTemplate gcNumber" placeholder="2 Digit Expiration Month" />
<input id="card_expire_year" name="cardExpireYear" class="inputRedTemplate gcPin" placeholder="4 Digit Year" />
<input id="card_zip" name="cardZip" class="inputRedTemplate inputFullWidth inputRoundedBottom" placeholder="Billing ZIP Code" />
</div>
<div class="btnRedTemplate btnFullWidth checkoutBtn floatLeft" style="margin-top:30px;" onclick="" title="Submit Button" />Submit</div>
</div>
我有以下腳本:
<script>
$(document).ready(function() {
hideAllPaymentBlocks();
})
function hideAllPaymentBlocks() {
$('#cashPaymentBlock').hide();
$('#ccPaymentBlock').hide();
// add line for checks, too
}
function displayPaymentFields() {
$('ccPaymentBlock').show();
}
</script>
的hideAllPaymentBlocks
功能正常運行就緒功能,但displayPaymentFields
似乎並不在點擊信用卡div來運行。沒有錯誤;它只是沒有做任何事情。任何人都可以將我指向正確的方向嗎?正如我所說,我一直在盯着這一段時間,我相信這是一個簡單的解決方案,但我無法讓我的大腦工作。
是的。我一直盯着它太久了!謝謝。 – EmmyS