gpt4 book ai didi

javascript - YII:通过 onclick 方法为变量赋值

转载 作者:行者123 更新时间:2023-12-03 10:17:11 25 4
gpt4 key购买 nike

下午好,我已经为这些问题苦苦挣扎了两天,但我的时间不多了......

我有这个模态...

    <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,模式的内容将会不同.. .

请提供任何帮助,我们将不胜感激

最佳答案

你可以像这样通过data-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>

我希望这会有所帮助。

关于javascript - YII:通过 onclick 方法为变量赋值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29810942/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com