从网格视图yii2设置href =“#”或取消设置html :: a href

时间:2015-09-03 02:36:30

标签: yii2 yii2-advanced-app yii2-basic-app

我有以下代码:

 [   'format' => 'raw',
            'contentOptions'=>['style'=>'width: 5px;'],
            'value' => function($model) {
                if($model->id == Yii::$app->user->identity->id) {
                    return  Html::a('<i class="glyphicon glyphicon-share-alt"></i>',[''],['id'=> 'replay-to-'. $model->ID_KOMENTAR ]).' '. 
                            Html::a('<i class="glyphicon glyphicon-pencil"></i>', ['update', 'id' => $model->id]).' '.
                            Html::a('<i class="glyphicon glyphicon-trash"></i>', ['delete', 'id' => $model->id], ['data' => ['confirm' => 'Do you really want to delete this element?','method' => 'post']]);
                }
                return Html::a('<i class="glyphicon glyphicon-share-alt"></i>',['feedback', 'id' => $model->id],['id'=> 'replay-to-'. $model->ID_KOMENTAR ]);
            },
        ],

我想重播按钮以避免使我的页面重定向到另一个页面的href,因为我想点击并将jquery放在那里。

我试过这个:

Html::a('<i class="glyphicon glyphicon-share-alt"></i>',[''],['id'=> 'replay-to-'. $model->ID_KOMENTAR ])

但它仍然会重定向到另一个页面。

2 个答案:

答案 0 :(得分:2)

href值设为#

Html::a('<i class="glyphicon glyphicon-share-alt"></i>', '#', ['id'=> 'replay-to-' . $model->ID_KOMENTAR]);

HTML输出将是:

<a id="replay-to-1" href="#"><i class="glyphicon glyphicon-share-alt"></i></a>

要完全删除href属性,请使用null(及其第二个参数的默认值):

Html::a('<i class="glyphicon glyphicon-share-alt"></i>', null, ['id'=> 'replay-to-' . $model->ID_KOMENTAR]);

HTML输出将是:

<a id="replay-to-1"><i class="glyphicon glyphicon-share-alt"></i></a>

答案 1 :(得分:1)

试试这个

rw------- 1 root root 3632 Sep 1 15:19 app.js drw------- 2 root root 4096 Sep 1 15:19 bin drw------- 3 root root 4096 Sep 3 08:56 config -rw------- 1 root root 326 Sep 1 15:19 deploy_doc.sh -rw------- 1 root root 419 Sep 1 15:19 gulpfile.js drw------- 3 root root 4096 Sep 1 15:19 lib drw------- 2 root root 4096 Sep 1 15:19 migrations drw------- 2 root root 4096 Sep 1 15:19 models drw------- 31 root root 4096 Sep 2 05:38 node_modules -rw------- 1 root root 1015 Sep 1 15:19 package.json drw------- 3 root root 4096 Sep 1 15:19 public -rw------- 1 root root 1591 Sep 1 15:19 README.md -rw------- 1 root root 168 Sep 1 15:19 redis_client.js drw------- 3 root root 4096 Sep 1 15:19 routes drw------- 6 root root 4096 Sep 1 15:19 test -rw------- 1 root root 256 Sep 1 15:19 test.sh drw------- 2 root root 4096 Sep 1 15:19 views