Twitter bootstrap 3工具提示在Yii框架中不起作用

时间:2014-06-21 14:23:00

标签: twitter-bootstrap yii twitter-bootstrap-3

我试图在Yii app中使用twitter bootstrap工具提示,但似乎无效。 Firebug控制台返回错误TypeError: $(...).tooltip is not a function。正如您在代码中看到的那样,包含了bootstrap.js文件。但是找不到这个功能,或许有什么东西可以覆盖它?我的默认布局main.php代码:

<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="language" content="en" />

    <!-- blueprint CSS framework -->
    <link rel="stylesheet" type="text/css" href="<?php echo Yii::app()->request->baseUrl; ?>/css/screen.css" media="screen, projection" />
    <link rel="stylesheet" type="text/css" href="<?php echo Yii::app()->request->baseUrl; ?>/css/print.css" media="print" />

    <!--[if lt IE 8]>
        <link rel="stylesheet" type="text/css" href="<?php echo Yii::app()->request->baseUrl; ?>/css/ie.css" media="screen, projection" />
        <![endif]-->

    <link rel="stylesheet" type="text/css" href="<?php echo Yii::app()->request->baseUrl; ?>/css/main.css" />
    <link rel="stylesheet" type="text/css" href="<?php echo Yii::app()->request->baseUrl; ?>/css/form.css" />
    <link rel="stylesheet" type="text/css" href="<?php echo Yii::app()->request->baseUrl; ?>/css/custom.css" />
    <link rel="stylesheet" type="text/css" href="<?php echo Yii::app()->request->baseUrl; ?>/css/bootstrap/bootstrap.css" />
    <link rel="stylesheet" type="text/css" href="<?php echo Yii::app()->request->baseUrl; ?>/css/custom_bootstrap.css" />

    <script type="text/javascript" src="<?php echo Yii::app()->request->baseUrl; ?>/js/jquery-2.1.1.min.js"></script>

    <script type="text/javascript" src="<?php echo Yii::app()->request->baseUrl; ?>/js/bootstrap.min.js"></script>
    <script type="text/javascript">
        jQuery(function() {
            $("a[data-toggle='tooltip']").tooltip();
        });
    </script>
    <title><?php echo CHtml::encode($this->pageTitle); ?></title>
</head>

// body code fragment in the same layout file------------------------------
                            <?php   
                            $this->widget('zii.widgets.CMenu', array(
                                'items' => array(
                                    array(
                                        'url' => array('/site/login'),
                                        'visible' => Yii::app()->user->isGuest,
                                        'linkOptions' => array('class' => 'btn btn-default navbar-btn tooltip_element',
                                            'data-toggle' => 'tooltip',
                                            'title' => 'login',
                                            'data-placement' => 'bottom')),
                                ),
                                'linkLabelWrapper' => 'span',
                                'linkLabelWrapperHtmlOptions' => array('class' => 'glyphicon glyphicon-log-in'),
                                'htmlOptions' => array('class' => 'nav navbar-nav',
                                ),
                            ));
                            ?> 

1 个答案:

答案 0 :(得分:0)

我想出了如何让它工作,添加了这段代码。

取而代之的是:

<link>...</link>

替换:

<?php $baseUrl = Yii::app()->request->baseUrl; $cd = Yii::app()->getClientScript(); $cd->registerScriptFile($baseUrl . '/js/bootstrap.min.js'); ?>