請嘗試使用下面的代碼片段。
<!DOCTYPE html>
<html>
<head>
<title>Test</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script>
$(document).ready(function() {
$('.SameAsBillingAddress').on('click',function(){
if($(this).prop('checked'))
{
$('.Address2').prop('disabled', true);
}
else
{
$('.Address2').prop('disabled', false);
}
});
});
</script>
</head>
<body>
<div>
<ul>
<div style="height:30px; width:80%; margin-left:30px; clear:both;">
<input name="" type="checkbox" value="" class="SameAsBillingAddress" />Same as Billing Address</div>
<li>
<label>House No.:</label>
<input type="text" name="house no" class="Address2" placeholder="House No" />
</li>
<li>
<label>Street:</label>
<input type="text" name="street" class="Address2" placeholder="Your Street" />
</li>
<li>
<label>City</label>
<input type="text" name="city" class="Address2" placeholder="Your City" />
</li>
<li>
<label>Zip:</label>
<input type="text" name="zip" class="Address2" placeholder="Your Zip" />
</li>
<li>
<label>Country:</label>
<select class="Address2">
<option>India</option>
</select>
</li>
<li style="float:right;">
<label></label>
<input type="submit" name="save" class="Address2" value="Save Details" />
</li>
</ul>
</div>
</body>
</html>
我建議輸入控件的作用域。這將禁用頁面上的所有文本輸入。 –
但我不想隱藏我的上邊輸入類型的地址 – Sam
你能解釋在JS小提琴 – Sam