2015-04-22 32 views
0

下午好,我一直在努力與這些2天,現在,我的時間不多了......誼:從OnClick方法

我有這個模式......將值分配給一個變量

<div class="modal-header"> 
    <a class="close" data-dismiss="modal">&times;</a> 
    <?php if ($modalToOpen == "1") { ?> 
     <h4>Aplicar abono a la cuenta #<?php echo $cardInformation->CardNumber ?></h4> 
    <?php } ?> 
    <?php if ($modalToOpen == "2") { ?> 
     <h4>Aplicar cargo a la cuenta #<?php echo $cardInformation->CardNumber ?></h4> 
    <?php } ?> 

</div> 

<div class="modal-body"> 
    <p>Saldo Actual: <?php echo $lastBalance ?></p> 
    <?php echo $modalToOpen ; if($modalToOpen == 1){ ?> 
    <?php $form = $this->beginWidget('bootstrap.widgets.TbActiveForm', array('id' => 'inlineForm', 'type' => 'inline', 'htmlOptions' => array('class' => 'well'))); ?> 
    <?php echo $form->TextField($auxModel, 'Payment', array('size' => 8, 'maxlength' => 8, 'placeholder' => "$. Abono", 'class' => 'span1')); ?> 
    <?php echo $form->TextField($auxModel, 'Coment', array('size' => 250, 'maxlength' => 250, 'placeholder' => "Comentario", 'class' => 'span3')); ?> 
    <?php 
    $this->widget(
      'bootstrap.widgets.TbButton', array(
      'buttonType' => 'ajaxButton', 
      'type' => 'primary', 
      'label' => 'Guardar', 
      'url' => Yii::app()->createUrl('BusinessTargetCollectionCard/ApplyPayment'), 
      'htmlOptions' => array('onclick' => 'showWait();','id' =>'payment-btn'. uniqid()), 
      'ajaxOptions' => array(
       'type' => 'POST', 
       'dataType' => 'json', 
       'data' => array(
        'cardNumber' => $cardInformation->CardNumber, 
        'lastBalance' => $lastBalance, 
        'coment' => 'js:$("#BusinessTargetCollectionCardMovement_Coment").val()', 
        'payment' => 'js:$("#BusinessTargetCollectionCardMovement_Payment").val()', 
        'businessTargetCollectionCardId' => $cardInformation->Id, 
        'collectorId' => $cardInformation->CollectorId), 
       'success' => 'js:function(data){ 
         alert(data.message); 
         if(data.status == "OK"){ 
          $("#PaymentModal").modal("hide"); 
          hideWait(); 
         } 
        }' 
      ), 
     ) 
    ); 
    $this->endWidget(); ?> 
    <?php } ?> 
    <?php if($modalToOpen == 2){ ?> 
    <?php $form = $this->beginWidget('bootstrap.widgets.TbActiveForm', array('id' => 'inlineForm', 'type' => 'inline', 'htmlOptions' => array('class' => 'well'))); ?> 
    <?php echo $form->TextField($auxModel, 'BalanceAfter', array('size' => 8, 'maxlength' => 8, 'placeholder' => "Cantidad a aplicar", 'class' => 'span1')); ?> 
    <?php 
    $this->widget(
      'bootstrap.widgets.TbButton', array(
       'buttonType' => 'ajaxButton', 
       'type' => 'primary', 
       'label' => 'Guardar', 
       'url' => Yii::app()->createUrl('BusinessTargetCollectionCard/ApplyCharge'), 
       'htmlOptions' => array('onclick' => 'showWait();', 'id' => 'charge-btn' . uniqid()), 
       'ajaxOptions' => array(
        'type' => 'POST', 
        'dataType' => 'json', 
        'data' => array(
         'cardNumber' => $cardInformation->CardNumber, 
         'charge' => 'js:$("#BusinessTargetCollectionCardMovement_BalanceAfter").val()'), 
        'success' => 'js:function(data){ 
          alert(data.message); 
          if(data.status == "OK"){ 
           $("#myModal").modal("hide"); 
           hideWait(); 
          } 
         }' 
       ), 
      ) 
    ); 
    $this->endWidget(); 
    ?> 
    <?php } ?> 

</div> 

,我有以下按鈕:

<td><?php 
      $this->widget(
        'bootstrap.widgets.TbButton', array(
        'label' => 'Aplicar cargo', 
        'type' => 'success', 
        'htmlOptions' => array(
         'onclick' => I dont know what to do // 'js:$("#modalToOpen").val("1");', 
         'data-toggle' => 'modal', 
         'data-target' => '#myModal', 
        ), 
       ) 
      ); 
      ?></td> 

     <td></td> 
     <td><?php 
      $this->widget(
        'bootstrap.widgets.TbButton', array(
        'label' => 'Aplicar pago', 
        'type' => 'primary', 
        'htmlOptions' => array(
         'onclick' => I dont know what to do //'js:$("#modalToOpen").val("2");', 
         'data-toggle' => 'modal', 
         'data-target' => '#myModal', 
        ), 
       ) 
      ); 
      ?></td> 

我想要做的是改變取決於的$modalToOpen值在其上點擊按鈕...這樣的模式的內容會有所不同,如果按鈕1是點擊或按鈕2 ...

請任何幫助將真正appreacciated

回答

1

你可以通過它通過數據ID這樣

<?php 
      $this->widget(
        'bootstrap.widgets.TbButton', array(
        'label' => 'Aplicar cargo', 
        'type' => 'success', 
        'htmlOptions' => array(
         'onclick' =>'js:function(data){ 
          var myvalue = $(this).data("id"); 
          $(".modal-body #myvalue").val(myvalue); 
           }', 
         'data-toggle' => 'modal', 
         'data-target' => '#myModal', 
         'data-id'=>'1', 
        ), 
       ) 
      ); 
      ?> 

採取價值在一個隱藏的文本或在

<div class="modal-body"> 
     <p>some content</p> 
     <input type="text" name="myvalue" id="myvalue" value=""/> 
</div> 

我希望這會有所幫助。