清单地址的重用

<!doctype html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>list</title>
	<style>
	*{margin:0; padding:0;}
	body{font-size: 12px; background-color: #fff; text-align:center;}
	input[type=text]{border:1px solid #ccc; height: 24px; line-height: 24px;}
	input[type=checkbox]{vertical-align: middle;}
	.f-wrap{width: 1000px; text-align: left; margin:0 auto; }
	h3{line-height: 30px;}
	form{padding:0 10px; }
	div{padding:5px 0;}
	</style>
	<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
	<script>
	$(document).ready(function(){
		$.fn.setReadOnly = function(readOnly){
			return this.filter('input:text')
						.attr('readOnly',readOnly)
						.css('opacity',readOnly ? 0.5 : 1.0 );
		}

		$('#address').find('legend').each(function(){
			$(this).replaceWith('<h3>' + $(this).text() + '</h3>');
		}).end()
			.on('click','#sameAddress',function(){
			var same = this.checked;
			if(same){
				$('#billAddress').val(same ? $('#shopAddress').val() : '');
				$('#billCity').val(same ? $('#shopCity').val() : '');
				$('#billState').val(same ? $('#shopState').val() : '');
				$('#billZip').val(same ? $('#shopZip').val() : '');
				$('#billingAddress input:text').setReadOnly(same);
				same = !same;
			}else{
				$('#billAddress').val(same ? $('#shopAddress').val() : '');
				$('#billCity').val(same ? $('#shopCity').val() : '');
				$('#billState').val(same ? $('#shopState').val() : '');
				$('#billZip').val(same ? $('#shopZip').val() : '');
				$('#billingAddress input:text').setReadOnly(same);
			}
		});
	});
	</script>
</head>
<body>
	<div class="f-wrap">
		<fieldset id="address">
			<legend>The test form</legend>
			<form action="" name="testForm">
				<div><label for="">First Name:</label><input type="text" name="firstName" id="firstName"></div>
				<div><label for="">Last Name:</label><input type="text" name="lastName" id="lastName"></div>
				<div id="shoppingAddress">
					<h2>shopping address</h2>
					<div><label for="">Street address:</label><input type="text" name="shopAddress" id="shopAddress"></div>
					<div>
						<label for="">City, State, Zip:</label>
						<input type="text" name="shopCity" id="shopCity">
						<input type="text" name="shopState" id="shopState">
						<input type="text" name="shopZip" id="shopZip">
					</div>
				</div>
				<div id="billingAddress">
					<h2>billing address</h2>
					<div>
						<input type="checkbox" id="sameAddress">
						Billing address is same as shopping address
					</div>
					<div><label for="">Street address:</label><input type="text" name="billAddress" id="billAddress"></div>
					<div>
						<label for="">City, State, Zip:</label>
						<input type="text" name="billCity" id="billCity">
						<input type="text" name="billState" id="billState">
						<input type="text" name="billZip" id="billZip">
					</div>
				</div>
			</form>
		</fieldset>
	</div>
</body>
</html>


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值