上週我剛剛開始學習HTML/CSS,javascript和jQuery,非常感謝您的幫助。 我用複選框(id #ship_to_billing)創建了一個表單,然後創建了一個包含5個文本字段的字段集(id #shipping_info)。使用JQuery我已經設置好了,如果複選框被選中,它會切換其他字段並隱藏它們。但是,我無法弄清楚如何另外需要一個或另一個,或者必須選中複選框或者必須完成字段集中的所有文本字段。我不需要警報。請幫忙!複選框選中後需要fieldset
謝謝大家提前,蘇珊
<a type="button" class="btn btn-primary" href="#product-options" data-
toggle="modal">Buy This!</a>
<div class="modal hide fade" id="product-options">
<div class="modal-header center">
<a class="close" data-dismiss="modal">x</a>
<h3>When, Where and How?</h3>
</div>
<div class="modal-body l-m">
{% include 'datepicker' %}
<p>
<input type="hidden" name="properties[ship_to_billing]" value="" />
<label for="ship_to_billing" style="max-width:335px;">
<input id="ship_to_billing" type="checkbox" name="properties[Ship to Billing Address]" value="Yes" {% if properties.ship_to_billing %} checked="checked"{% endif %} />
<font size=1>Check here to have items shipped to your billing address (collected during checkout). Otherwise please fill out the information below.</font>
</label><br />
</p>
<div class="fieldgroup" id="shipping_info">
<label for="shipping_name">Name of Recipient:</label>
<input class="input-xlarge" type="text" id="shipping_name" placeholder="Name" name="properties[Recipient]" required="required" />
<p>
<label for="address_street">Shipping Address:</label>
<input class="input-xlarge" type="text" id="address_street" placeholder="Street Address" name="properties[Address]" required="required" />
<input class="input-xlarge" type="text" id="address_city" placeholder="City" name="properties[City]" required="required" />
<input class="input-medium" type="text" id="address_province" placeholder="State" name="properties[State]" required="required" />
<input class="input-medium" type="text" id="address_zip" placeholder="Zip Code" name="properties[Zip]" required="required" />
</p>
</div>
<p>
<label for="gift_msg">Gift Message :</label>
<textarea id="gift_msg" placeholder="Please type your message" name="properties[Gift Message]" rows="4" cols="45"></textarea>
</p>
</div>
<div class="modal-footer">
<div class="btn-group">
<button href="#" class="btn" data-dismiss="modal">Cancel</button>
<button type="submit" onclick="return validateShipping();" class="btn btn-primary" id="addtocart">Add To Cart</button>
</div>
</div>
</div>
JQUERY:
<script>
$('#ship_to_billing').change(function(){
$('#shipping_info').toggle('show');
});
</script>
所以我正確地假設,如果複選框被選中,然後字段消失?對不起,如果這是一個有點迂迴;) –
@ChrisKempen我相信複選框被初步檢查。 – silvenon
我不確定我是否理解這個問題。 「額外需要」是什麼意思?複選框必須被選中或者必須填寫字段爲什麼? – silvenon