我上周刚开始学习 HTML/CSS、javascript 和 jQuery,非常感谢一些帮助。我创建了一个带有复选框(id #ship_to_billing)的表单,然后是一个包含 5 个文本字段的字段集(id #shipping_info)。我使用 JQuery 进行了设置,如果选中该复选框,它会切换其他字段并隐藏它们。但是,我不知道如何另外需要一个或另一个,要么必须选中复选框,要么必须完成字段集中的所有文本字段。我不需要警报。请帮忙!
提前谢谢大家,苏珊
<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>
查询:
<script>
$('#ship_to_billing').change(function(){
$('#shipping_info').toggle('show');
});
</script>