javascript - Yii2 通过点击链接加载模态

标签 javascript php jquery twitter-bootstrap yii2

这是我的_form

<div class="row">       
    <div class="col-sm-4">
        <?= $form->field($model, 'otm_grading_system')->dropdownList(ot\TestGradingSystem::getTestGradingSystem(), [
            'prompt' => Yii::t('ot', '--- Select Grading System ---'),
            'onchange' => '$.get( "'.Url::toRoute('dependent/get-grading-system').'", { id : $(this).val() }).done(function(data) {
                $( "#seeHere").html(data);
            });'
        ]) ?>
    </div>
    <div class="col-sm-4" id="seeHere">
    </div>
</div>

在表单 dropDownList 中更改事件获取 url。下面显示DependandController.php

class DependentController extends \yii\web\Controller
{
  public function actionGetGradingSystem($id)
  {
     return Html::a('See Here 123', ['test-grading-system/view', 'id' => $id], ['id' => 'seeHereMdl', 'title' => Yii::t('ot', 'View Result')]);
  }
}

这是模态加载js

<?php
  $this->registerJs(
   "$(document).on('ready pjax:success', function() {
     $('#seeHereMdl').click(function(e){
       e.preventDefault();      
       $('#grading-sys-modal').modal('show')
                  .find('.modal-content')
                  .load($(this).attr('href'));  
       });
     });
   ", $this::POS_HEAD);
?>
<?php
  yii\bootstrap\Modal::begin([
    'id'=>'grading-sys-modal',
    'size' => 'modal-lg'
  ]);
   yii\bootstrap\Modal::end();
?>

我的问题是无法在模式中加载 View 文件,但它会重定向到此 View 页面。

最佳答案

这是一个事件处理问题(与yii无关),而不是:

$('#seeHereMdl').click(function(e){});

你应该简单地尝试:

$('body').on('click', '#seeHereMdl', function(e) {});

了解更多:Event binding on dynamically created elements?

关于javascript - Yii2 通过点击链接加载模态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37224585/

相关文章:

javascript - 在 Javascript contenteditable div 中插入文本

javascript - VueJS 打印 HTML 到页面

php - 我无法使用 PHP 在 Excel 电子表格上显示 "11e5"

javascript - 在同一个元素上调用 Mustache 两次失败?

javascript - 在将 Jquery 附加到 div 后,如何使用 Jquery 修改 css 元素?

javascript 模块模式适用于 jsbin,但不适用于我的服务器/浏览器

javascript - 使用随机键循环 json

javascript - 使用ajax加载表单然后再次使用ajax提交

php - MySQL 查询在新的 phpmyadmin 上不起作用

php - 仅在 div 中加载 php 内容