自定义包装器:(
function($){
$.fn.setReadOnly = function(readnoly){
alert('123');
return this.filter('input:text')
.attr('readonly',readonly)
.css('opacity',readonly?0.5:1.0);
}
}
)(jQuery);
调用页面:<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
<script src="jquery-1.4.js" type='text/javascript'></script>
<script src="JQuery.Fn.js" type='text/javascript'></script>
<script type='text/javascript'>
$(
function(){
$('#sameAddressControl').click(
function(){
var same = this.checked; $('#billAddress').val(same?$('#shipAddress').val():'');
$('#billCity').val(same?$('#shipCity').val():'');
$('#billState').val(same?$('#shipState').val():'');
$('#billZip').val(same?$('#shipZip').val():'');
$('#billingAddress input').setReadOnly(same);
}
);
}
);
</script>
</head>
<body>
<fieldset>
<legend>The Test Form</legend>
<div>
<from name='testForm'>
<div>
<label>First name :</label>
<input type='text' name='firstName' id='firstName'/>
</div>
<div>
<label>Last name :</label>
<input type='text' name='lastName' id='lastName'/>
</div>
<div id='shippingAddress'>
<h2>Shipping address</h2>
<div>
<label>Street adress :</label>
<input type='text' name='shipAddress' id='shipAddress'/>
</div>
<div>
<label>City,state,zip:</label>
<input type='text' name='shipCity' id='shipCity'/>
<input type='text' name='shipState' id='shipState'/>
<input type='text' name='shipZip' id='shipZip'/>
</div>
</div>
<div id='billingAddress'>
<h2>Billing addres</h2>
<div>
<input type='checkbox' id='sameAddressControl'/>
Billing address is same as shipping address
</div>
<div>
<label>Street adress :</label>
<input type='text' name='billAddress' id='billAddress'/>
</div>
<div>
<label>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>
</from>
</div>
</fieldset>
</body>
</html>为什么调用的包装器没有效果啊?谢谢!