<script>
     /*配件JS*/
    void function(){     var updateAdjunctPrice=function(){
           var adjunctPrice=0;           var selected=$$('#goods-adjunct tr').filter(function(tr,index){                       return tr.getElement('input[type=checkbox]').checked;           });
           selected.each(function(s,i){
               adjunctPrice+=s.get('price').toFloat()*s.getElement('input[type=hidden]').value.toFloat();
   //alert(s.get('price').toFloat()*s.getElement('input[type=hidden]').value)
           });
           var price=isNaN(adjunctPrice)?0:adjunctPrice;
           $E('#goods-adjunct .price').set('text',priceControl.format(price));
      };        var adjunctCheckbox=$ES('#goods-adjunct input[type=checkbox]');
        var adjunctText=$ES('#goods-adjunct input[type=text]');
        adjunctCheckbox.addEvent('click',function(e){
              var  prt=this.getParent('tr');
              var  min_num=prt.getParent('tbody').get('min_num').toInt();
              if(isNaN(min_num)||min_num<1)min_num=1;              var _hidden=prt.getElement('input[type=hidden]').set('disabled',!this.checked);              this.checked?prt.setStyle('background','#e9e9e9'):prt.setStyle('background','#fff');              var _text=prt.getElement('input[type=text]');              if(!_text.value||_text.value<min_num){                _hidden.value=_text.value=min_num;
              }else{
                _hidden.value=_text.value;
              }
              updateAdjunctPrice();        });        adjunctText.addEvent('keydown',function(e){
          if($A(keyCodeFix).include(e.code).length>25)
           e.stop();
        });
        adjunctText.addEvent('keyup',function(e){
              var  prt=this.getParent('tr');
              var min_num=prt.getParent('tbody').get('min_num').toInt();
              var max_num=prt.getParent('tbody').get('max_num').toInt();
              var _hidden=prt.getElement('input[type=hidden]');
              if(isNaN(min_num)||min_num<0){
                 min_num=0;
              };
              if(isNaN(max_num)||max_num<0){
                 max_num=Number.MAX_VALUE;
              };
              if(this.value){
                _hidden.value=this.value=this.value.toInt().limit(min_num,max_num);
              }
              updateAdjunctPrice();
        });    }();  </script>

解决方案 »

  1.   

    我查过了,但还是很多地方不懂
    例如选择器,我不明白他是如何选择的
    $$('#goods-adjunct tr')
    我把TR改成 DIV 就失效了
      

  2.   


    这个倒没什么。可能是重新定义$了。基本可以定义成任何字符的,你暂且当一个$理解.
    $$('#goods-adjunct tr')
    这个是找id为goods-adjunct下面所有的tr元素。$$('#goods-adjunct tr').size()会得到在id为goods-adjunct下面有多少行,一般情况下是table下面的tr.你改成div就会去找div元素
      

  3.   


    #goods-adjunct 和 tr 是父子关系, id 为 goods-adjunct 下没有 div吧,楼主应该 用的 prototype 还是 mootools?
      

  4.   

    明白了,谢谢楼上的 
    id 为 goods-adjunct 下有 DIV 
      

  5.   

    return tr.getElement('input[type=checkbox]').checked;
    这句的 TR是什么意思啊?
    var  prt=this.getParent('tr');
    还有这句