提示:引擎收录链接已经被插入在我最后的评论显示了
提示:穆罕默德的解决方案仍然无法正常工作(见新的工具提示的图片)!
我的布局文件编码是这样的:
<?php
use yii\helpers\Html;
use common\wsl_components\AdminLteAsset;
$js = <<<SCRIPT
$(function () {
$('body').tooltip({
selector: '[data-toggle="tooltip"]',
html:true
});
});
SCRIPT;
// Register tooltip/popover initialization javascript
$this->registerJs($js);
AdminLteAsset::register($this);
$this->beginPage()
?>
<!DOCTYPE html>
<html lang="<?= Yii::$app->language ?>">
<head>
<meta charset="<?= Yii::$app->charset ?>"/>
<meta name="viewport" content="width=device-width, initial-scale=1">
<?= Html::csrfMetaTags() ?>
<title><?= Html::encode($this->title) ?></title>
<?php $this->head(); ?>
</head>
<body class="hold-transition skin-blue sidebar-mini sidebar-collapse">
<?php $this->beginBody(); ?>
<div class="wrapper">
<?=
$this->render(
'header.php'
);
?>
<?=
$this->render(
'left.php'
);
?>
<?=
$this->render(
'content.php', ['content' => $content]
);
?>
</div>
<?php $this->endBody(); ?>
</body>
</html>
<?php $this->endPage(); ?>
我GridView
编码是这样的:
[
'attribute' => $dummy ,
'label' => Yii::t ( 'app' , 'Charakterisierung' ) ,
'format' => 'html' ,
'value' => function($model) {
if ( !empty ( $model->person->personentypDominant->typ_name )) {
$tag = Html::tag ( 'span' , 'Tooltip-Touch Me!' , [
// html-tags won't be rendered in title
'title' => $model->person->personentypDominant->typ_empfehlung ,
'data-placement' => 'left' ,
'data-toggle'=>'tooltip',
'style' => 'white-space:pre;border:1px solid red;'
] );
return $tag . "<br>" . $model->person->personentypDominant->typ_verhaltensmerkmal_im_team_1 . "," . $model->person->personentypDominant->typ_verhaltensmerkmal_bei_stress_3 . "," . $model->person->personentypDominant->typ_verhaltensmerkmal_am_arbeitsplatz_4;
}
}
],
然而,HTML标签的工具提示将不会被渲染。他们的出现,因为他们在数据库,比如像这样:
Verhaltensempfehlung:<br><ul><li>
Kompetenz und Selbstbewusstsein zeigen,</ul></li>
我不知道为什么,但上面的标签不会被解释。他们在工具提示硬编码。任何想法,我做错了什么?
编辑:穆罕默德已经回答了我的问题是完全一样的,但答案没有解决我的问题!为了显示我的问题,看attachement,请!
你有2级明显的错误
view
您提供149
你缺少的跨度属性data-toggle="tooltip"
行。
他们改变
$tag_rot = Html::tag(
'span', 'Typ Rot', [
'title' => $tooltip_rot,
'data-toggle' => 'tooltip',
'data-placement' => 'left',
'style' => 'white-space:pre;border:2px solid red;'
]
);
$tooltip_green = \common\modules\lookup\models\LPersonentyp::findOne(2)->typ_empfehlung;
$tag_green = Html::tag(
'span', 'Typ Grün', [
'title' => $tooltip_green,
'data-toggle' => 'tooltip',
'data-placement' => 'left',
'style' => 'white-space:pre;border:2px solid green;'
]
);
$tooltip_blue = \common\modules\lookup\models\LPersonentyp::findOne(3)->typ_empfehlung;
$tag_blue = Html::tag(
'span', 'Typ Blau', [
'title' => $tooltip_blue,
'data-toggle' => 'tooltip',
'data-placement' => 'left',
'style' => 'white-space:pre;border:2px solid blue;'
]
);
"format"=>"html"
而你应该用"format"=>"raw"
列定义更改为以下
[
'attribute' => $dummy ,
'label' => Yii::t ( 'app' , 'Charakterisierung' ) ,
'format' => 'raw' ,
'value' => function($model) {
if ( !empty ( $model->person->personentypDominant->typ_name ) ) {
$tag = Html::tag ( 'span' , 'Tooltip-Touch Me!' , [
'title' => $model->person->personentypDominant->typ_empfehlung ,
'data-placement' => 'left' ,
'data-toggle' => 'tooltip' ,
'style' => 'white-space:pre;border:1px solid red;'
] );
return $tag . "<br>" . $model->person->personentypDominant->typ_verhaltensmerkmal_im_team_1 . "," . $model->person->personentypDominant->typ_verhaltensmerkmal_bei_stress_3 . "," . $model->person->personentypDominant->typ_verhaltensmerkmal_am_arbeitsplatz_4;
}
}
] ,
我以前给ANSWER
更侧重对与html::tag()
工具提示使用,我用你的代码的GridView列复制粘贴,忘了在使用的GridView内的情况下,有一说,我已经更新了这个问题的答案了。
在情况下,如果你仍然无法实现@Muhammad奥马尔阿斯拉姆的回答后,提示中的HTML视图。
'data-html' => 'true'
或者JS方式$(selector).tooltip({html: true})
注:根据自举官方文件Use text if you're worried about XSS attacks.
$(selector).tooltip({
content: function () {
return this.getAttribute("title");
},
});
In this link你可以找到其他方式解决jQeuer的UI提示