YII:从onclick方法为变量赋值

时间:2015-04-22 23:42:52

标签: javascript php jquery yii

下午好,我现在已经挣扎了2天,而且我已经没时间了......

我有这种模式......

<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

我想要做的是根据点击的按钮更改#ifndef NUMBERLIST_H #define NUMBERLIST_H class NumberList { private: //declares a structure for the list struct ListNode { double value; // value in the node struct ListNode *next; //to point to the next node }; ListNode *head; // list head pointer public: // construcorr NumberList() { head = nullptr; } ~NumberList(); //linked list operations void appendNode(double); void insertNode(double); void deleteNode(double); void dispayList()const; }; void NumberList::appendNode(double num) { ListNode *newNode; ListNode *nodePtr; //allocate a new node and store num there newNode = new ListNode; newNode->value = num; newNode->next = nullptr; //if there are no nodes in the listmake newNode first node if (!head) head = newNode; else // otherwise insert newNode at end { //initialize nodePtr to head of list nodePtr = head; //find the last node in the list while (nodePtr->next) nodePtr = nodePtr->next; // insert newNode as the last node nodePtr->next = newNode; } } #endif 的值...因此,如果单击按钮1或按钮2,则模态的内容将不同...

请任何帮助将真正适用

1 个答案:

答案 0 :(得分:1)

You can pass it through data-id like this

<?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',
                    ),
                )
            );
            ?>

take that value in one hidden or text in

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

I hope this will help.