当前位置:嗨网首页>书籍在线阅读

09-解决方案1

  
选择背景色: 黄橙 洋红 淡粉 水蓝 草绿 白色 选择字体: 宋体 黑体 微软雅黑 楷体 选择字体大小: 恢复默认

10.2.2 解决方案1

如果你想要做的只是禁用账单字段,在 change 事件触发时使用 jQuery .attr().removeAttr() 方法就可以做到:

//寻找"sameAsShipping"复选框,监听change事件
$('#sameAsShipping').change(function(){
   if( this.checked ){
     //寻找billingInfo内的所有文本输入字段,禁用它们
     $('#billingInfo input:text').attr('disabled','disabled');
   } else {
     //寻找billingInfo内的所有文本输入字段,启用它们
     $('#billingInfo input:text').removeAttr('disabled');
   }
}).trigger('change'); // close change() then trigger it once